By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

#else not working

P: n/a
Hi everybody!

I'm having a very strange behaviour on my pre-processor. Basically I
have the following piece of code:

#if (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 4)) \
|| defined(_POSIX2_C_VERSION) \
|| (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L))
#include <unistd.h>
#else
extern "C"
{
#include "getopt.h"
}
#endif

.... the goal is to use the system's implementation of the getopt()
function if it is available (that's why those tests are there) or use
the sample implementation that came with Visual Studio 6.0 in the
remaining cases (e.g., on Windows).

On Windows 2000 + Visual Studio .NET 2003, everything works fine.

On HP-UX B.11.11 U + gcc 3.4.2, I get the following error:

In file included from effdoc.cpp:3:
precomp.h:29:20: getopt.h: No such file or directory
*** Error exit code 1

Stop

.... this is very strange as the pre-processor macros tested should make
the contents of the if clause expand, not the else clause:

_XOPEN_VERSION = 4
_POSIX_VERSION = 199309
_POSIX2_C_VERSION = 199209

.... does anyone have an idea of what's going on?

Any help greatly appreciated.

André

Jul 6 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ho********@yahoo.com wrote:
I'm having a very strange behaviour on my pre-processor. Basically I
have the following piece of code:

#if (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 4)) \
>>defined(_POSIX2_C_VERSION) \
(defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L))
#include <unistd.h>
#else
extern "C"
{
#include "getopt.h"
}
#endif

[..]

On HP-UX B.11.11 U + gcc 3.4.2, I get the following error:

In file included from effdoc.cpp:3:
precomp.h:29:20: getopt.h: No such file or directory
*** Error exit code 1

Stop

... this is very strange as the pre-processor macros tested should
make the contents of the if clause expand, not the else clause:

_XOPEN_VERSION = 4
_POSIX_VERSION = 199309
_POSIX2_C_VERSION = 199209

... does anyone have an idea of what's going on?
I bet HP Tech Support does.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 6 '06 #2

P: n/a
hobbes_7_8 wrote:
#if (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 4)) \
|| defined(_POSIX2_C_VERSION) \
|| (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L))
This is not a preprocessor issue, it's a "code-too-complex"
issue.

Break it up:

#define XOPEN (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 4))
#define POSIX2 (defined(_POSIX2_C_VERSION))
#define POSIX (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L))

Now you can use #warning XOPEN or similar to temporarily print out the
intermediate values.

Then put them back together:

#if XOPEN || POSIX2 || POSIX

Much more readable.

--
Phlip
Jul 6 '06 #3

P: n/a
Actually, the fact that this is running on an HP-UX system only
indirectly makes those pre-processor macros have the values they have.
And that's it.

This is a problem regarding the behaviour of the pre-processor, which
is part of gcc. Therefore HP support is not the one to be called.

Jul 7 '06 #4

P: n/a

<ho********@yahoo.comwrote in message
news:11*********************@s53g2000cws.googlegro ups.com...
Actually, the fact that this is running on an HP-UX system only
indirectly makes those pre-processor macros have the values they have.
And that's it.
And that's...what?
>
This is a problem regarding the behaviour of the pre-processor, which
is part of gcc. Therefore HP support is not the one to be called.
_What's_ a problem with the pre-processor?

It would help if you quoted what you're replying to.

Do you still need help? If so, you might take the suggestion from Philip
and break down those #defines into smaller pieces. You might then also want
to take those defined values and check them individually (such as with their
own #ifdef sections, wrapping some kind of statements which you can easily
recognize, such as error or warning statements). Then you can test exactly
what's going on. It just might be that your assumption about one or more of
those values is incorrect.

(I'm also wondering: do those \ line continuation markers apply to #if
statements? They might be causing the problem. Just a thought.)

-Howard

Jul 7 '06 #5

P: n/a
ho********@yahoo.com wrote:
Hi everybody!

I'm having a very strange behaviour on my pre-processor. Basically I
have the following piece of code:

#if (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 4)) \
|| defined(_POSIX2_C_VERSION) \
|| (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L))
#include <unistd.h>
#else
extern "C"
{
#include "getopt.h"
}
#endif

In file included from effdoc.cpp:3:
precomp.h:29:20: getopt.h: No such file or directory
*** Error exit code 1
Are you sure that the #else is being executed? Perhaps unistd.h
includes getopt.h .

Supposing it is: are you sure that those macros are actually
defined at this point? What headers did you include previously
to this #if statement? You might like to use other #ifdef tests
to check if the macros are actually defined as you think they are.

Jul 10 '06 #6

P: n/a
Hi everybody!

I found what the problem was. Basically I was testing pre-processor
macros in order to determine if I should include unistd.h. Well, it
happens those macros were defined in unistd.h itself :S

I had to make an awkward statement (see below), but the fact is that it
now works.

Thanks for the tips, anyway!

André
--
#if defined(unix) || defined(__unix) || defined(__unix__)
#include <unistd.h>
#endif
#if (defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 4)) \
|| defined(_POSIX2_C_VERSION) \
|| (defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L))
// getopt was added to <unistd.hin XPG4 and POSIX 1003.2
#else
extern "C"
{
#include "getopt.h"
}
#endif

Jul 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.