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

hi why can not i us #if in the macro?

hi all,

what's the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif

when i compiled it in vs.net, it complains

c99.cpp(12) : error C2162: formal paramer of macro needed
c99.cpp(17) : error C2059: syntax error : "constant"
c99.cpp(17) : error C2065: "endif" : undeclared symbol
i don;t know why.

Nov 14 '05 #1
12 4021
"baumann@pan" <ba*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
what's the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif


You cannot use preprocessor directives in a #define. That is just the way
the language is defined. If you explain what you are trying to achieve,
maybe someone can suggest an alternative solution.

Alex
Nov 14 '05 #2
In article <11**********************@z14g2000cwz.googlegroups .com>,
baumann@pan <ba*********@gmail.com> wrote:
what's the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif


You seem to be expecting the macro to expand into something containing
the #if directive, but it doesn't work like that.

The lines are pasted together first, producing

#define COMMENT_LINE(p) #if 0 (p);#endif

which is syntactically incorrect.

-- Richard
Nov 14 '05 #3
baumann@pan wrote on 11/04/05 :
what's the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif
This is not C. You can't have proprocessor thingies in macros (# is
already used for something else).
when i compiled it in vs.net, it complains

c99.cpp(12) : error C2162: formal paramer of macro needed


Your extension should be .c if you intent to compile a C source.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"

Nov 14 '05 #4
In article <mn***********************@YOURBRAnoos.fr>,
Emmanuel Delahaye <em***@YOURBRAnoos.fr> wrote:
when i compiled it in vs.net, it complains c99.cpp(12) : error C2162: formal paramer of macro needed
Your extension should be .c if you intent to compile a C source.


That's usually true in practice -- but it's not part of the
standard ;-)
--
"Who Leads?" / "The men who must... driven men, compelled men."
"Freak men."
"You're all freaks, sir. But you always have been freaks.
Life is a freak. That's its hope and glory." -- Alfred Bester, TSMD
Nov 14 '05 #5
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote:
baumann@pan wrote on 11/04/05 :
what's the problem of the macro below?

#define COMMENT_LINE(p) \
#if 0\
(p);\
#endif


This is not C. You can't have proprocessor


_Pre_processor.
when i compiled it in vs.net, it complains

c99.cpp(12) : error C2162: formal paramer of macro needed


Your extension should be .c if you intent to compile a C source.


Depends on the compiler, surely? With gcc, this is true, but that means
nothing for any other compiler.

Richard
Nov 14 '05 #6
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> wrote:
baumann@pan wrote on 11/04/05 : [...]
> when i compiled it in vs.net, it complains
>
> c99.cpp(12) : error C2162: formal paramer of macro needed


Your extension should be .c if you intent to compile a C source.


Depends on the compiler, surely? With gcc, this is true, but that means
nothing for any other compiler.


Most C compilers (all the ones I know of) use ".c" as the normal
suffix for C source files; ".cpp" is probably C++. Yes, it depends on
the compiler, but it's a widespread convention.

--
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.
Nov 14 '05 #7
Mark McIntyre wrote on 15/04/05 :
On Fri, 15 Apr 2005 06:15:37 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Your extension should be .c if you intent to compile a C source.


Depends on the compiler, surely? With gcc, this is true, but that means
nothing for any other compiler.


microsoft copmilers assume its C++ unless its suffix is .c. Some sun
compilers differentiate between .C and .c.


Eclipse/CDT for example...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"C is a sharp tool"

Nov 14 '05 #8
Keith Thompson wrote on 15/04/05 :
Somewhat OT, but most Unix compilers use ".c" for C source and either
".C" or ".cpp" for C++ source. (Windows compilers don't use ".C" for
C++ because the file system can't distinguish between ".C" and ".c".)


Windows XP does, and you must be careful when using Eclipse/CDT,
because .C invokes g++...

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

..sig under repair

Nov 14 '05 #9
On Fri, 15 Apr 2005 21:31:37 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:
On Fri, 15 Apr 2005 06:15:37 GMT, in comp.lang.c ,
rl*@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Your extension should be .c if you intent to compile a C source.

Depends on the compiler, surely? With gcc, this is true, but that means
nothing for any other compiler.


microsoft copmilers assume its C++ unless its suffix is .c. Some sun
compilers differentiate between .C and .c.


Somewhat OT, but most Unix compilers use ".c" for C source and either
".C" or ".cpp" for C++ source. (Windows compilers don't use ".C" for
C++ because the file system can't distinguish between ".C" and ".c".)


that should read "couldn't, prior to about 1999". All modern windows
OSen can do this quite handily, though the command interpreter still
is too stupid.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #10
On Sat, 16 Apr 2005 08:39:58 +0200, in comp.lang.c , "Emmanuel
Delahaye" <em***@YOURBRAnoos.fr> wrote:
Keith Thompson wrote on 15/04/05 :
Somewhat OT, but most Unix compilers use ".c" for C source and either
".C" or ".cpp" for C++ source. (Windows compilers don't use ".C" for
C++ because the file system can't distinguish between ".C" and ".c".)


Windows XP does, and you must be careful when using Eclipse/CDT,
because .C invokes g++...


the reason I mentioned this is because we just got bitten on the a*se
by precisely this 'bug'. We ported a library back from Solaris to XP,
and the compile kept falling over mysteriously...
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #11
Mark McIntyre <ma**********@spamcop.net> writes:
On Fri, 15 Apr 2005 21:31:37 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:

[...]
Somewhat OT, but most Unix compilers use ".c" for C source and either
".C" or ".cpp" for C++ source. (Windows compilers don't use ".C" for
C++ because the file system can't distinguish between ".C" and ".c".)


that should read "couldn't, prior to about 1999". All modern windows
OSen can do this quite handily, though the command interpreter still
is too stupid.


Still a bit OT ...

Yes, Windows distinguishes between ".c" and ".C", but not in the same
way that Unix does. A file name retains whatever case was specified
when it was created, but you can't have two files in the same
directory named "foo.c" and "foo.C"; if you have a file called
"foo.c", you can successfully open it either as "foo.c" or as "foo.C".

Presumably this means that you can compile a given source file either
as C or as C++ just by changing the name by which you refer to it
(without actually changing the name of the file). (I say "presumably"
because I don't actually use Windows compilers.) Not a huge deal, but
something to watch out for.

To make it topical, all this stuff affects the semantics of fopen(),
which is part of the reason the C standard doesn't say much about what
file names look like other than being strings.

--
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.
Nov 14 '05 #12
On Sun, 17 Apr 2005 20:34:18 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Yes, Windows distinguishes between ".c" and ".C", but not in the same
way that Unix does. A file name retains whatever case was specified
when it was created, but you can't have two files in the same
directory named "foo.c" and "foo.C"; if you have a file called
"foo.c", you can successfully open it either as "foo.c" or as "foo.C".
FWIW I seem to recall that you can, but creating them via the
high-level functions or command line gui is pretty tricky.
Presumably this means that you can compile a given source file either
as C or as C++ just by changing the name by which you refer to it
(without actually changing the name of the file). (I say "presumably"
because I don't actually use Windows compilers.) Not a huge deal, but
something to watch out for.


In fact no - all the compilers I know of are case-insensitive when it
comes to filenames. This hs coincidentally how I know of this issue -
we had some C++ we ported from solaris & linux back to windows, and a
couple of files didn't compile properly with gcc. Turned out they were
named ".C".
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
Nov 14 '05 #13

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

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
2
by: Pete | last post by:
In Access 95/97 I used to be able to create pull down menus (File,Edit ...) from a macro. It seems there used to be some wizard for that. However in Access 2000 it seems you have to build your...
7
by: Newbie_sw2003 | last post by:
Where should I use them? I am giving you my understandings. Please correct me if I am wrong: MACRO: e.g.:#define ref-name 99 The code is substituted by the MACRO ref-name. So no overhead....
3
by: Alexander Ulyanov | last post by:
Hi all. Is it possible to pass the whole blocks of code (possibly including " and ,) as macro parameters? I want to do something like: MACRO(FOO, "Foo", "return "Foobar";", "foo();...
8
by: lasek | last post by:
Hi...in some posts i've read...something about using macro rather then function...but difference ??. Best regards....
12
by: Laurent Deniau | last post by:
I was playing a bit with the preprocessor of gcc (4.1.1). The following macros expand to: #define A(...) __VA_ARGS__ #define B(x,...) __VA_ARGS__ A() -nothing, *no warning* A(x) -x ...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
5
by: Bill | last post by:
This database has no forms. I am viewing an Access table in datasheet view. I'd like to execute a macro to execute a function (using "runcode"). In the function, I'll reading data from the record...
0
by: =?Utf-8?B?TGV0emRvXzF0?= | last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines, remove some lines based upon a condition in a certain column. Then copy this data into a new spreadsheet and sort the ...
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: 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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.