Pelles C forum

Pelles C => Bug reports => Topic started by: Prokrust on January 18, 2021, 11:19:56 AM

Title: _Pragma() not handle concatination of string literals
Post by: Prokrust on January 18, 2021, 11:19:56 AM
Not compile
_Pragma("startup " "func1");

error #1052: Syntax error in '_Pragma' operator.
error #2001: Syntax error: expected ')' but found 'string constant'.
Title: Re: _Pragma() not handle concatination of string literals
Post by: Prokrust on January 20, 2021, 03:14:04 PM
//This is a complete example of a compilation error
//macros ZINITIALIZE(init) compile _Pragma("startup" "init")

#include <stdio.h>
#include <stdlib.h>

#ifdef __POCC__
#define WIN32_DEFAULT_LIBS
#define __STDC_WANT_LIB_EXT1__  1
#define ZINITIALIZE(NameInit)  _ZINITIALIZE1(NameInit)
#define _ZINITIALIZE1(NameInit)  _ZINITIALIZE2(NameInit)
#define _ZINITIALIZE2(NameInit)  _Pragma("startup " #NameInit)

#elif defined(__MINGW64__)
#define ZINITIALIZE(NameInit)  void __cdecl NameInit(void) __attribute__((constructor))
#endif
void init(void);

int main(int argc, char *argv[]) {
   return 0;
}

ZINITIALIZE(init);
//_Pragma("startup" "init");
void init(void) {
   printf("Init!\n");
}
Title: Re: _Pragma() not handle concatination of string literals
Post by: Pelle on January 25, 2021, 09:09:29 PM
Not a bug. String concatination doesn't work in this context.
Title: Re: _Pragma() not handle concatination of string literals
Post by: Prokrust on January 26, 2021, 11:24:04 AM
Not a bug. String concatination doesn't work in this context.
Ok.
Unfortunately the alternative doesn't work either:
Code: [Select]
#include <stdio.h>
#define ZINITIALIZE(NameInit)  _ZINITIALIZE1(startup NameInit)
#define _ZINITIALIZE1(NameInit)  _Pragma(#NameInit)


int main(int argc, char *argv[]) {
//struct ArrayInt arr[] = {{0}};
//printf("TT %i\n",arr[0].size);
    return 0;
}

void init(void) {
   printf("Init!\n");
}
ZINITIALIZE(init);

#define ZMACROS_ASSERT(...)  _Static_assert(0, _ZMACROS1(__VA_ARGS__))
#define _ZMACROS1(P1)  #P1

//ZMACROS_ASSERT(ZINITIALIZE(init));
//_Pragma("startupinit");
Analysis via ZMACROS_ASSERT shows:_Pragma("startupinit");
PS.
_Static_assert only outputs about 500 characters in the error message. Can I increase this number? This will simplify the analysis of  large macros.
Title: Re: _Pragma() not handle concatination of string literals
Post by: Pelle on January 29, 2021, 07:28:30 PM
Unfortunately the alternative doesn't work either:
Analysis via ZMACROS_ASSERT shows:_Pragma("startupinit");
Right. Internally there is a "virtual space" before the second token that is lost during stringizing. I will fix this for the next version. Unfortunately I can't think of an easy workaround for now...

_Static_assert only outputs about 500 characters in the error message. Can I increase this number? This will simplify the analysis of  large macros.
After recent changes I needed to add conversions between UTF-8 and UTF-16 just before output (for Windows API). I already had a "fallback" buffer of 1024 bytes (in case dynamic buffer allocations fail), so tempting to use that. Everything else is in dynamic memory, so this should be too. I will fix this for the next version.