473,378 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

#else not working

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
6 1577
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
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
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

<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
4
by: Simon | last post by:
Hi there I know I should be able to do this, but I'm stuck! I am trying to build a table that forms from cats being pulled from a DB. The table will be 3 cols by x rows. I have been doing...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
11
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at...
14
by: tbird2340 | last post by:
I want to write an if / then statement and have tried using this: var MyVarMailto; if (Request.Form("LoanRequest") == "Under $250,000") { if (Request.Form("Organization") == "1") { MyVarMailto...
12
by: SA SA | last post by:
I know it is me but i can not get this condition to work. Regardless of Check or credit card it always defaults to else portion of the script. I can't get if (login.PMT_INDICATOR.value == "C") to...
7
by: reon | last post by:
In the below code.. else statements didnt work correctly... the program is to add the positive and negative numbers... if we enter alphabets it will show the wrong entry ,, but thats not...
2
by: pradeep.thekkottil | last post by:
I'm setting up an auction website using PHP and MySQL. There in the section where logged in members can put up new auction in a form, I want to run a form validation where I used if else statements...
5
by: kavithadevan | last post by:
Hi, Here is the script which i am working in this script i am trying to search some events for that i developed this .Its working but if there is no events means i want to display there is no...
2
by: epsilon | last post by:
All: I'm running into trouble figuring this one out. It seems that my decision routine is not working as intended. Does anyone know why my output continues to utilize the "else" portion of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.