News:

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

Main Menu

_Pragma

Started by PVozenilek, February 11, 2017, 04:55:32 PM

Previous topic - Next topic

PVozenilek

Pelles C supports _Pragma from C99. Unfortunately it is buggy.


#include <stdio.h>
static int i = 0;
static void __cdecl foo(void) {
  ++i;
}
#pragma startup foo // this works, i gets incremented


// this fails to compile
#define BAR() \
  static void __cdecl bar(void) { ++i; } \
  _Pragma("startup bar") \
  /**/

   
BAR()

int main(void)
{
  printf("i = %d\n", i);
  return 0;
}


Compiler error is:

Building a.obj.
O:\a\a.c(17): warning #2099: Missing type specifier; assuming 'int'.
O:\a\a.c(17): error #2001: Syntax error: expected ')' but found 'string constant'.
O:\a\a.c(17): error #2001: Syntax error: expected ';' but found ')'.
O:\a\a.c(17): warning #2135: Static 'bar' is not referenced.
*** Error code: 1 ***
Done.



I had tried all the tricks: adding/removing parenthesis, semicolon, putting the _pragma before/after. Nothing helped.