By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,192 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,192 IT Pros & Developers. It's quick & easy.

regarding #define

P: n/a
I have come across some preprossor statements, such as

#define PPTR_int
#define PPTR_str
#define DDAR_baddr &
#define DDAR_caddr &
What do they mean, but when i compile the code with these i
am not getting any errors .
How about the #define format. " #define variable constant" , what the
meaning of the first four #define's with out constant value. Why the
compiler is not giving errors.
Thanks,
Vikas.

Mar 15 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
venkat said:
I have come across some preprossor statements, such as

#define PPTR_int
#define PPTR_str
#define DDAR_baddr &
#define DDAR_caddr &
What do they mean, but when i compile the code with these i
am not getting any errors .
The first two simply define a couple of symbols which will be replaced
by the empty string when the preprocessor gets hold of them.

For example, the code

int PPTR_int main(void)

will be translated as

int main(void)

Believe it or not, this can be useful. For example, I used to work on a
system where we used the same code on the mainframe and on the PC,
except for one header.

On the mainframe, we had this code in the platform-specific header:

#define PACKED _packed

whereas on the PC, we had this code:

#define PACKED

which should look familiar to you, since it's the same kind of code as
you're asking about.

All our structs were defined like this:

PACKED struct foo
{
whatever...
};

On the PC, the PACKED quietly disappeared (because of the way it was
defined), and we packed our structs using a compiler switch. On the
mainframe, there was no such switch, but there was this _packed keyword
instead, so we used that.

You will probably find that the code you're asking about is doing much
the same thing.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 15 '07 #2

P: n/a
On Mar 15, 10:39 am, "venkat" <venkatavi...@gmail.comwrote:
I have come across some preprossor statements, such as

#define PPTR_int
#define PPTR_str
#define DDAR_baddr &
#define DDAR_caddr &
Oh Code from vovida.org !
>
What do they mean,
consider of #define as String replacement.
>but when i compile the code with these i
am not getting any errors .
How about the #define format. " #define variable constant" , what the
meaning of the first four #define's with out constant value. Why the
compiler is not giving errors.
if your compiler supports Only precompilation you can checkout what is
the output of Precompilation
and which string is replaced by which one ?
>
Thanks,
Vikas.
--Raxit

Mar 15 '07 #3

P: n/a
On Mar 15, 10:39 am, "venkat" <venkatavi...@gmail.comwrote:
I have come across some preprossor statements, such as

#define PPTR_int
#define PPTR_str
#define DDAR_baddr &
#define DDAR_caddr &

What do they mean, but when i compile the code with these i
am not getting any errors .
Dont you ever seen code like ?
#define DEBUG
How about the #define format. " #define variable constant" , what the
meaning of the first four #define's with out constant value. Why the
compiler is not giving errors.

Thanks,
Vikas.
--Raxit

Mar 15 '07 #4

P: n/a
venkat wrote, On 15/03/07 05:39:

<snip>
How about the #define format. " #define variable constant" , what the
meaning of the first four #define's with out constant value. Why the
compiler is not giving errors.
The replies I've seen so far don't point out what I consider to be a
serious misunderstanding you have about #define.

#define does *not* create a variable by any meaning of the word I know,
and the second parameter is *not* a constant in the normal sense of the
word.

The word "variable" typically implies that there is somewhere that a
value is stored. The work "constant" typically implies there is some a
value. Neither of these concepts really applies that well to macro
definitions when you are thinking about the C program. Macro's have all
disappeared a long time before the compiler worries about where to store
values.

A macro is simply a method of doing textual substitution, a bit like
using the "search and replace" feature in your favourite text editor.
The macro definition does not even have to make sense, for example...

#define this is a very silly macro definition

There are ways the above *could* be used.

Macros can also be used to define code fragments.

I suggest you read a decent C text book, and I would be suspicious of
the reference you are currently using if it talks about macro
definitions as you have shown as "#define variable constant". It might
be good, but I am suspicious of it.
--
Flash Gordon
Mar 15 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.