About Macro

R

Remo

Hi All

I Have Quation About Macro's plz help

why do we have # symbol before any macro line #define STOP 0 ...

why con't we use the any other symbol like $, @,,

plz answer if any one knows reason.

Thanks & Regards
Remo
 
S

santosh

Remo said:
Hi All
I Have Quation About Macro's plz help

why do we have # symbol before any macro line #define STOP 0 ...
why con't we use the any other symbol like $, @,,

plz answer if any one knows reason.

Thats simply the way the C preprocessor works. It scans the source file
for lines that begin with the '#' character and takes the rest of that
line as it's directive.

If you really want to use someother character, feel free to modify the
source of any free cpp implementation or write your custom preprocessor
as a plugin replacement, but it that case, your programs will no longer
be C programs.
 
E

Eric Sosman

Remo said:
Hi All

I Have Quation About Macro's plz help

why do we have # symbol before any macro line #define STOP 0 ...

why con't we use the any other symbol like $, @,,

We can!

??=include <stdio.h>
??=define POUND_SIGN "Octothorpe"
int main(void) {
printf(POUND_SIGN " is unnecessary!\n");
return 0;
}
 
N

Naresh

Wow! this is strange! Is it an anomaly or a loophole?
Cant we use #define to redefine the symbol #??

Regards,
 
C

Chris Dollin

Naresh said:
Wow! this is strange! Is it an anomaly or a loophole?

Please don't top-post.

Eric had said:

It's not an anomaly [1] nor is it a loophole. It's a trigraph.
Cant we use #define to redefine the symbol #??

No, we can't. #define can only define macros with names which are,
er, names.

[1] Well, you /could/ say trigraphs-as-a-whole count as an anomoly.
 
J

Jordan Abel

Naresh said:
Wow! this is strange! Is it an anomaly or a loophole?

Please don't top-post.

Eric had said:

It's not an anomaly [1] nor is it a loophole. It's a trigraph.
Cant we use #define to redefine the symbol #??

No, we can't. #define can only define macros with names which are,
er, names.

[1] Well, you /could/ say trigraphs-as-a-whole count as an anomoly.

Digraphs are much better. %:define ...
 
K

Keith Thompson

Remo said:
I Have Quation About Macro's plz help

why do we have # symbol before any macro line #define STOP 0 ...

why con't we use the any other symbol like $, @,,

plz answer if any one knows reason.

Because that's how the language syntax is defined. Why would you want
to use a different symbol?
 
A

August Karlstrom

Keith said:
Because that's how the language syntax is defined. Why would you want
to use a different symbol?

I think Remo's question is quite clear and I'm surprised by all strange
answers. Let me rephrase the question as I interpret it:

Is there any particular reason why the number sign was chosen as a
prefix for preprocessor directives? Tradition?


August
 
J

Jordan Abel

I think Remo's question is quite clear and I'm surprised by all strange
answers. Let me rephrase the question as I interpret it:

Is there any particular reason why the number sign was chosen as
a prefix for preprocessor directives? Tradition?

It was available. About the only symbols in ASCII that aren't used for
SOMETHING in C are $, @, and `, none of which are in the base character
set [But then, i suspect neither would #, if it weren't used.] # and
$ are a bit "safer" than @ and `, vs national variants, and maybe it was
a coin toss between them. $ is used in system-specific identifiers on
some implementations, but i think the original preprocessor use of
# came before those.
 
B

Ben Bacarisse

I think Remo's question is quite clear and I'm surprised by all strange
answers. Let me rephrase the question as I interpret it:

Is there any particular reason why the number sign was chosen as a
prefix for preprocessor directives? Tradition?

It is just possible that is is an echo from TRAC -- a general purpose
macro processing language designed by Mooers and Deutch in about 1966
which used # as the main macro marker IIRC. TRAC was intellectually
ingenious and very popular in the early 70s when C and its preprocessor
emerged. Only the original cpp authors can say if they had this in mind.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C macro 3
Macro Mystery ... help? 4
Defining macro on the command-line vs in the source 3
preprocessor macro problem 3
Macro 12
MACRO help 23
question about macro? 23
How macro is preprocessed 3

Members online

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top