News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

conio.h trouble

Started by PhilG57, October 07, 2025, 10:18:00 PM

Previous topic - Next topic

PhilG57

Trying to rebuild an old program and now get complaints about conio.h:

C:\Program Files\Pelles C\Include\conio.h(50): error #2019: Invalid use of __declspec(vaformat).

Line 50 in conio.h looks like:

extern _CRTIMP _CRTCHK(printf,1,2) int __cdecl _cprintf(const char * restrict, ...);

The code with which I am working looks like this:

   #include <conio.h>      /* for textcolor and backgroundcolor */
   _textcolor(1);   /* dark blue; very hard to see */
   fprintf(stderr, "rlog %s: ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789\n\r", gszCmdId);
   _textcolor(2);   /* green; very hard to see */

I googled __declspec and saw references to C++ and MSVC but couldn't really figure out anything.  What am I doing wrong?  Thanks.

Pelle

The _CRTCHK(printf,1,2) part of line 50 will expand from this:
#define _CRTCHK(f,n,m)  __declspec(vaformat(f,n,m))which normally works fine with Pelles C.

I'm not sure why things are failing for you. Wild guess: do you have a conflicting #define printf somewhere?
/Pelle

PhilG57

This is only thing I see:

 :-[ Find "define printf".
"C:\Users\philg\Documents\C Programming\RCSW\Native Windows_04_11_2020\config.h" (196)   #define  printf_string( m, n )      __attribute__ ( ( format (printf, m, n ) ) )
"C:\Users\philg\Documents\C Programming\RCSW\Native Windows_04_11_2020\config.h" (198)   #define  printf_string( m, n )
"C:\Users\philg\Documents\C Programming\RCSW\Native Windows_04_11_2020\config.h" (203)   #define  printf_string_exiting( m, n )   __attribute__ ( ( format (printf, m, n ), noreturn ) )
"C:\Users\philg\Documents\C Programming\RCSW\Native Windows_04_11_2020\config.h" (205)   #define  printf_string_exiting( m, n )   printf_string ( m, n )
4 hit(s)

This code, these modules, are ancient and originally written as console programs. 

Pelle

__declspec() is a Microsoft invention (I think) used by the compiler to attach extra attributes to a function or data object.
I see you found __attribute__() which is GNU's way of doing the same thing (more or less).

I'm starting to wonder if you are mixing include files (*.h) from different C compilers...? This is a pretty sure way of getting weird problems.

If you suspect this is the case, try adding the compiler option /V1 for more during compilation. The path for "stdio.h" should be to the directory where Pelles C (and only Pelles C) is installed.
/Pelle