PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

#if statements and comments in pgcc

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
DavidMcMullin



Joined: 16 Feb 2006
Posts: 2

PostPosted: Fri Feb 17, 2006 4:11 am    Post subject: #if statements and comments in pgcc Reply with quote

Hi,

pgcc gives errors and refuses to compile when I use #if statements like the following:

#if (CONDITION)
codeToRun();
#endif

Also it doesn't seem to accept c++ style // comments.

Is it possible to make it accept either of these?

david
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6119
Location: The Portland Group Inc.

PostPosted: Fri Feb 17, 2006 10:17 am    Post subject: Reply with quote

Hi David,

Can you post a sample code which gives the error? Below is a test program which shows various methods of using conditional preprocessor directives, including "#if (CONDITIONAL)". Note that you can't use parentheses after "#ifdef/#ifndef".

C++ style-comments are not part of the K&R or C89 standards, so are not allowed by default. However, adding the "-B" flag tells the compiler to allow C++ comments. The C99 standard does allow C++ comments, so using the "-c9x" flag also works.

- Mat

Code:
% cat prepro.c
#include <stdio.h>

// This is a C++ comment

int main () {

#if (MY_DEF == 2)
  printf("MY_DEF == 2\n");
#endif

#if MY_DEF > 2
  printf("MY_DEF > 2\n");
#endif

#if (MY_DEF)
  printf("MY_DEF is %d\n", MY_DEF);
#endif

#if (defined(MY_DEF))
  printf("MY_DEF is %d\n", MY_DEF);
#endif

#ifdef MY_DEF
  printf("MY_DEF is %d\n", MY_DEF);
#endif

#ifndef MY_DEF
  printf("MY_DEF is not defined\n");
#endif

}
% pgcc -DMY_DEF prepro.c
PGC-S-0030-Syntax error: Malformed function or data declaration at '/' (prepro.c: 3)
PGC-S-0029-Syntax error: Recovery attempted by deleting from '/' on line 3 through identifier comment on line 3 (prepro.c)
PGC/x86-64 Linux/x86-64 Rel Dev: compilation completed with severe errors
% pgcc -DMY_DEF -B prepro.c
% a.out
MY_DEF is 1
MY_DEF is 1
MY_DEF is 1
% pgcc -DMY_DEF=10 -c9x prepro.c
% a.out
MY_DEF > 2
MY_DEF is 10
MY_DEF is 10
MY_DEF is 10
Back to top
View user's profile
DavidMcMullin



Joined: 16 Feb 2006
Posts: 2

PostPosted: Mon Feb 20, 2006 4:01 am    Post subject: Reply with quote

Thanks! There were no problems after I added the -B flag; it must have been giving the error on the #if statements because it was confused by the comments.

cheers
dave
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group