Page 1 of 1

Compiler macros

Posted: Thu Mar 08, 2012 2:59 pm
by SFSxOI
MS compilers have pre-defined macros like the (_WIN64) macro. Never thought about it before, but I was wondering what predefined, if any, macros the PB compiler has?

Re: Compiler macros

Posted: Thu Mar 08, 2012 4:25 pm
by Shield
There are pre-defined constants, e.g. #PB_COMPILER_DATE that do the same job.

Re: Compiler macros

Posted: Thu Mar 08, 2012 7:59 pm
by freak

Re: Compiler macros

Posted: Thu Mar 08, 2012 8:42 pm
by c4s
Offtopic:
@freak
Adding html anchors to the online and offline help would be useful. This way e.g. http://www.purebasic.com/documentation/ ... -constants or selecting the title from the navigation menu would directly jump to the bottom. It can be easily implemented using the id attribute (info here: http://www.w3.org/TR/html4/struct/links.html#h-12.2.3).

Re: Compiler macros

Posted: Fri Mar 09, 2012 1:29 pm
by SFSxOI
Thanks for the replys folks, not exactly what I was talking about but close enough I guess. :)

Re: Compiler macros

Posted: Fri Mar 09, 2012 2:26 pm
by xorc1zt
pb devs should add the macro __COUNTER__ which could be usefull.

Code: Select all

#include <stdio.h>

int curCounter = 0;

#define RESET_COUNTER curCounter = __COUNTER__ + 1
#define GET_COUNTER __COUNTER__ - curCounter

int main()
{
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   RESET_COUNTER;
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   RESET_COUNTER;
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   printf (" %d\n", GET_COUNTER );
   return 0;
}
result
0
1
2
3
4
5

0
1
2

0
1
2
3
4
5

Re: Compiler macros

Posted: Fri Mar 09, 2012 5:45 pm
by c4s
@xorc1zt
Well, there is the #PB_Compiler_EnumerationValue constant. Not exactly what you wanted but maybe you didn't know it so far:

Code: Select all

  Enumeration
    #GadgetInfo ; Will be 0
    #GadgetText ; Will be 1
    #GadgetOK   ; Will be 2
  EndEnumeration
  
  Enumeration #PB_Compiler_EnumerationValue
    #GadgetCancel ; Will be 3
    #GadgetImage  ; Will be 4
    #GadgetSound  ; Will be 5
  EndEnumeration