For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

[Bug report -- syntax error]

Massimo Del Fedele's picture
Forums: 

In OSD_FileNode.cxx, from line 17 :

#if!defined(TM_IN_SYS_TIME) && defined(HAVE_TIME_H)
# include
#elif HAVE_SYS_TIME_H
# include
#endif

#elif HAVE_SYS_TIME_H should be replaced with #elif defined(HAVE_SYS_TIME_H)

Max

Forum supervisor's picture

Dear Massimo,
You are welcome to develop a corresponding patch and make a contribution via the Collaborative portal - http://dev.opencascade.org/index.php?q=home/get_involved.
This will benefit all.
Regards

Roman Lygin's picture

Guys,

To be clear.

This is not a bug and the results will be the same.
#if _MACRO_ is equivalent to #ifdef _MACRO_ or #if defined(_MACRO_) as long as _MACRO_ is not 0.
The only value add in this case will be syntax consistency.

I myself tend to prefer #if _MACRO_ syntax as it's shorter and more flexible.
Roman

Massimo Del Fedele's picture

I don't know if it should be the same, but with GCC it isn't.
On my system the compiler complains about this as an error,
not a warning.
I know that usually I can write #if or #ifdef, but I'm not sure about #elif.

Max

Roman Lygin's picture

This just means you HAVE_SYS_TIME_H is either undefined (and hence #else defined won't help) or it is default as 0.
Anyway, you might want to check config.h.

Massimo Del Fedele's picture

#else defined DO help, because if I change it it works without any syntax error.

------------------------------------------------------
#define SOMETHING
#define ANOTHERTHING

int main(int argc, const char *argv[])
{
int a;
#ifdef SOMETHING
a = 1;
#elif ANOTHERTHING a = 2;
#else
a = 3;
#endif

------------------------------
int main(int argc, const char *argv[])
{
int a;
#ifdef SOMETHING
a = 1;
#elif defined(ANOTHERTHING) a = 2;
#else
a = 3;
#endif

Max

Roman Lygin's picture

Argh, my bad!

Should be
#else if
of course. #elif with undefined macro leads to error of course.

Sorry for confusion.

Massimo Del Fedele's picture

np. :-)
It's the first time I encounter this kind of bug... I wasn't sure either.
Usually for configuration macros I prefere to use #ifdef, which allow macro defined
with any value, rather than #if which requires to be != 0, but it's a matter of taste, I guess.

BTW, IMHO c preprocessor is missing some #elifdef macro :-)

Max

Denis Barbier's picture

Hello, your fix is right, but I compile OCC with different versions of GCC and never encountered this error, so I am curious: what is your GCC error message exactly, and which version of GCC do you use?

Massimo Del Fedele's picture

Hi Denis,

the error is exactly the one I've reported : "error: #elif with no expression"

The GCC is the one supplied with Ubuntu Natty, 4.6.1.

When I made my tests I've seen that error happens only in some conditions, depending on which of both variables are #defined (don't remember exactly when....); if you run my test sample above you'll get the error. Probably if you use the

#define XXXXX 1
instead of the
#define XXXXX

you won't get the error... but I'm not sure about.
I found it because I'm using a custom config file.

Max