473,395 Members | 1,692 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,395 software developers and data experts.

#if command at header file

hi to all,
why when i use the command

#define test 10
#define X test;
#if (test == X) ....
......


The test is fail always when the statment at header file?
if this statment is found at c file the test work
how can i make it work(and still use defines)?
Pristo

Dec 5 '05 #1
8 4477
>#define test 10
#define X test;
#if (test == X) ....
.....
The test is fail always when the statment at header file?
if this statment is found at c file the test work
how can i make it work(and still use defines)?


Manually expand it: does this line make any sense?

#if (test; == ) ...

From this, you should be able to tell which character to get rid of.

Gordon L. Burditt
Dec 5 '05 #2
In article <11**********************@g43g2000cwa.googlegroups .com>,
pristo <Ma*******@gmail.com> wrote:
why when i use the command #define test 10
#define X test;
#if (test == X) ....
..... The test is fail always when the statment at header file?
if this statment is found at c file the test work
how can i make it work(and still use defines)?


It should fail either way: the semicolon at the end of the X
definition is not valid preprocessor test syntax.

It fails either way for me for gcc 3.3 and SGI IRIX C 7.3.1.2m
--
Prototypes are supertypes of their clones. -- maplesoft
Dec 5 '05 #3
"pristo" <Ma*******@gmail.com> writes:
why when i use the command

#define test 10
#define X test;
#if (test == X) ....
.....


The test is fail always when the statment at header file?
if this statment is found at c file the test work
how can i make it work(and still use defines)?


You haven't given us enough information to guess what the problem
might be.

Post your actual code (preferably reduced to a few lines) and show us
what the output is and how it differs from what you expected it to be.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 5 '05 #4
go****@hammy.burditt.org (Gordon Burditt) writes:
#define test 10
#define X test;
#if (test == X) ....
.....
The test is fail always when the statment at header file?
if this statment is found at c file the test work
how can i make it work(and still use defines)?


Manually expand it: does this line make any sense?

#if (test; == ) ...

From this, you should be able to tell which character to get rid of.


But since he's seeing different behavior in a .h file vs. in a .c
file, I'm guessing that the code he posted bears only a superficial
resemblance to the code he's actually compiling. The semicolon
*might* be his problem, or it could be something else entirely.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 5 '05 #5
Gordon Burditt wrote:
#define test 10
#define X test;
#if (test == X) ....
.....
The test is fail always when the statment at header file?
if this statment is found at c file the test work
how can i make it work(and still use defines)?


Manually expand it: does this line make any sense?

#if (test; == ) ...

From this, you should be able to tell which character to get rid of.

Gordon L. Burditt

it a type mistake i write a new smaple code

file1.h
#define PARAM1 10
#define PARAM2 20
#define PARAM3 30
end of file1.h
file2.h
#define TEST1 PARAM2
end of file2.h

file3.h
#if (TEST1 == PARAM2)
...
#else
...
#endif
end of file3.h
- if i put the same code of file3.h at c file the #if statment will
work fine else its not work
thanks for helping
Pristo

Dec 5 '05 #6
pristo wrote:
file1.h
#define PARAM1 10
#define PARAM2 20
#define PARAM3 30

file2.h
#define TEST1 PARAM2

file3.h
#if (TEST1 == PARAM2)
...
#else
...
#endif
end of file3.h

- if i put the same code of file3.h at c file the #if statment will
work fine else its not work


In file3.h you have to write:
#include "file1.h"
#include "file2.h"

before anything else, and you have to either make sure that file1.h
and file2.h do NOT include file3.h, or use header guards (if you
don't know what header guards are, then do a google search).

Dec 5 '05 #7
"pristo" <Ma*******@gmail.com> writes:
[...]
it a type mistake i write a new smaple code

file1.h
#define PARAM1 10
#define PARAM2 20
#define PARAM3 30
end of file1.h
file2.h
#define TEST1 PARAM2
end of file2.h

file3.h
#if (TEST1 == PARAM2)
...
#else
...
#endif
end of file3.h
- if i put the same code of file3.h at c file the #if statment will
work fine else its not work
thanks for helping


You still need to show us *exactly* what you're trying to do. I
presume you don't literally have "..." lines in file3.h; what's really
there? You say it doesn't work; what exactly does that mean? What
does it do, and what did you expect it to do?

You're not showing us the actual code that you're compiling, just a
summary of it. The error is somewhere in what you're not showing us.
Don't try to guess what information you think we need.

Here's an example of the level of detail we need:

==================== file1.h ====================
#define PARAM1 10
#define PARAM2 20
#define PARAM3 30
=================================================

==================== file2.h ====================
#define TEST1 PARAM2
=================================================

==================== file3.h ====================
#if (TEST1 == PARAM2)
const char *message = "ok";
#else
const char *message = "error";
#endif
=================================================

==================== main1.c ====================
#include <stdio.h>
#include "file1.h"
#include "file2.h"
#include "file3.h"

int main(void)
{
printf("message = \"%s\"\n", message);
return 0;
}
=================================================

==================== main2.c ====================
#include <stdio.h>
#include "file1.h"
#include "file2.h"

#if (TEST1 == PARAM2)
const char *message = "ok";
#else
const char *message = "error";
#endif

int main(void)
{
printf("message = \"%s\"\n", message);
return 0;
}
=================================================

When I compile "main1.c" and execute the resulting program, the output is
message = "ok"
When I compile "main2.c" and execute the resulting program, the output is
message = "ok"
(identical to the output of main1).

This doesn't exhibit an error; if it did, I'd also specify what output
I expected to see.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 5 '05 #8
"Old Wolf" <ol*****@inspire.net.nz> writes:
pristo wrote:
file1.h
#define PARAM1 10
#define PARAM2 20
#define PARAM3 30

file2.h
#define TEST1 PARAM2

file3.h
#if (TEST1 == PARAM2)
...
#else
...
#endif
end of file3.h

- if i put the same code of file3.h at c file the #if statment will
work fine else its not work


In file3.h you have to write:
#include "file1.h"
#include "file2.h"

before anything else, and you have to either make sure that file1.h
and file2.h do NOT include file3.h, or use header guards (if you
don't know what header guards are, then do a google search).


If the main program has

#include "file1.h"
#include "file2.h"
#include "file3.h"

you can get away with not having headers include other headers. It's
poor style, of course, since it places obscure constraints on what
your main program has to do. The best approach is for each file to
include just what it needs, and to use include guards as necessary to
avoid including a header more than once, but I don't think that's the
OP's problem. (But I'm only guessing, since we still haven't seen the
code he's actually compiling.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 5 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: salerno.david | last post by:
I want to run a program from the program im writing. For example when my program is running I want it to open up an internet explorer window. I have been searching and found that there is a RUN...
2
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
34
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
4
by: nadz | last post by:
hey guys, I know bit of C++. I have installed Microsoft Visual C++ 2005 express. First of all tell me if it is of any use ? My other question is that I am trying to execute this command...
5
by: no_spam_for_gman | last post by:
I have been using the export command for quite some times to export comma delimited file. I have always been looking at how to generate the first row with the column header but never found a clean...
0
by: vc6 | last post by:
I am using Visual C++ 2005 Express Edition. Inside the IDE, when modifying a header file (aka "include" or ".h") the change is recognized by the builder such that it will recompile that file...
0
by: vc6 | last post by:
When I compile my project (using Visual C++ 2005 Express Edition) in the IDE, any change that I make in a header file, causes recompilation of every .cpp file that #includes that file. This is good...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
12
by: eric dexter | last post by:
I want to compare what I get on the command line in winmain with an if statement.. I am getting a beginers error but I don't have an example to use to fix it.. cannot convert from 'const int' to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.