what is size of this macro?

  • Thread starter venkatesh.k.desai5
  • Start date
F

Frederick Gotham

(e-mail address removed) posted:
#define PI 3.12


It's about an inch and a half wide on my screen.

If you need it smaller, try changing screen resolution -- should shave off a
few clock cycles.
 
V

venkatesh.k.desai5

But how is it? compiler will allocate memory.
Tak-Shing Chan said:
3.12 is of type double, therefore sizeof PI is the same as
sizeof(double).

Tak-Shing
 
C

Christopher Benson-Manica

Vlad Dogaru said:
Mine shows 3.14, but maybe your's is late. Are the batteries dead? ;)

It's 3.00 on mine, but I'm running on a King Solomon model, so
apparently it's a QOI issue.
 
J

J. J. Farrell

Coz macro's are processed in CPP.

You are asking questions which don't make much sense, and making
statements which don't seem to be related to the questions or the
discussion. This suggests that you have some fundamental
misunderstanding of something. If you give a more complete description
of what is puzzling you, perhaps with some example code, we may be
better able to help you understand the issue.
 
K

Keith Thompson

#define PI 3.12

Please put the question in the body of your article. Not all newsreaders
show the subject along with the body of the message.

The question was "what is size of this macro?". As you say later,
you're asking how much memory is allocated.

The answer is none. Macros don't allocate memory; they perform
textual substitution on your source code.

By itself, the macro definition

#define PI 3.12

will simply disappear from your program if you don't use it.

If you do use it, each occurrence of PI in your source will simply be
replaced with 3.12. What this does depends on how you use it.

The literal 3.12 is of type double, if that's what you were wondering about.
 
E

Eric Sosman

I mean how much memory it will take?

"None." Or "sizeof(double)." Or "too much." All
these answers, and more, are defensible. The question
is not well-formed, and suggests that you may not quite
understand what macros are or how they operate in your
program source. I recommend that you return to your C
textbook and re-read the section on macros, and perhaps
write a few short programs with and without using macros
(other than those you simply cannot avoid if you want to
use the library functions). If things remain unclear,
come back and ask more questions -- but the question you
are asking now indicates there's a basic flaw somewhere
in your understanding.
 
R

Richard Heathfield

(e-mail address removed) said:
Coz macro's are processed in CPP.

So what makes you think the compiler will allocate memory for PI? It won't
even /see/ PI, because - as you say - macros are processed by the
preprocessor.
 
J

Joe Wright

> But how is it? compiler will allocate memory.

The compiler doesn't involve itself in #define thingies. The compiler
never sees PI. The preprocessor has already replaced PI with 3.12 and,
correct or not, this is what the compiler eventually sees.
 
K

Keith Thompson

Joe Wright said:
The compiler doesn't involve itself in #define thingies. The compiler
never sees PI. The preprocessor has already replaced PI with 3.12 and,
correct or not, this is what the compiler eventually sees.

That's assuming that you don't consider the preprocessor to be part of
the "compiler".
 
R

Richard Bos

Christopher Benson-Manica said:
It's 3.00 on mine, but I'm running on a King Solomon model, so
apparently it's a QOI issue.

It certainly is: the King Solomon Specification only specifies a single
digit of precision, so your model is giving you a precision that isn't
actually justified by the docs.

Richard
 
A

Ancient_Hacker

I mean how much memory it will take?


How much memory will WHAT take, when, and on which compiler, what
platform?

Choices for "what" and "when":

(1) The line of text, in the source file.
(2) The macro, in the compiler, at compile time.
(3) The macro, at link time.
(3) The macro, at run time

You may need to read up on macros, and exactly how they get processed.
 

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

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top