Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > hi why can not i us #if in the macro?

Reply
Thread Tools

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

 
 
baumann@pan
Guest
Posts: n/a
 
      04-11-2005
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.

 
Reply With Quote
 
 
 
 
Alex Fraser
Guest
Posts: n/a
 
      04-11-2005
"baumann@pan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      04-11-2005
In article <(E-Mail Removed) .com>,
baumann@pan <(E-Mail Removed)> 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
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      04-14-2005
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"

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      04-14-2005
In article <(E-Mail Removed)>,
Emmanuel Delahaye <(E-Mail Removed)> 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
 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      04-15-2005
"Emmanuel Delahaye" <(E-Mail Removed)> 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
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-15-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) (Richard Bos) writes:
> "Emmanuel Delahaye" <(E-Mail Removed)> 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) (E-Mail Removed) <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.
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      04-15-2005
On Fri, 15 Apr 2005 06:15:37 GMT, in comp.lang.c ,
(E-Mail Removed) (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.

Yuck.
--
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 =----
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-15-2005
Mark McIntyre <(E-Mail Removed)> writes:
> On Fri, 15 Apr 2005 06:15:37 GMT, in comp.lang.c ,
> (E-Mail Removed) (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".)

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <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.
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      04-16-2005
Mark McIntyre wrote on 15/04/05 :
> On Fri, 15 Apr 2005 06:15:37 GMT, in comp.lang.c ,
> (E-Mail Removed) (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"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why :: ? Why not : ? Why not . ? <- less clutter ?!? Skybuck Flying C++ 16 08-25-2007 09:48 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
Can someone tell me why I can't delete this file? and why it blue screens WinXP Pro on delete? zZz Computer Support 1 01-12-2005 02:37 AM



Advertisments