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

Macro without string to substitute

P: n/a
Hello!!!

I have been using C for a very short while. I am used to macros in C,
but while i was reading the code for LittleOS (an open source OS), i
came across a type of macro wherein no value was given to substitute
the text. What does this imply? The code i came across is as follows:

#ifndef _TIME_H
#define _TIME_H

struct time {
int sec, min, hour;
};

struct date {
int dayofweek, day, month, year;
};

void gettime(struct time*);
void getdate(struct date*);
#endif
what does this do? Please Help

Casanova...

Nov 14 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sun, 21 Nov 2004 11:00:18 -0800, Casanova wrote:
Hello!!!

I have been using C for a very short while. I am used to macros in C,
but while i was reading the code for LittleOS (an open source OS), i
came across a type of macro wherein no value was given to substitute
the text. What does this imply? The code i came across is as follows:

#ifndef _TIME_H
#define _TIME_H

struct time {
int sec, min, hour;
};

struct date {
int dayofweek, day, month, year;
};

void gettime(struct time*);
void getdate(struct date*);
#endif
what does this do? Please Help
You don't need to supply a replacement list with #define, if you don't the
macro expands to nothing but, in this example, "defined _TIME_H" will
return 1 and text after "#ifdef _TIME_H" will be processed.

In the example above, the common technique of "header guards" is being
used where a header will only be processed if certain macro is not
defined. Before the header is processed the first time, the macro will be
(hopefully) undefined, the file will be processed and the macro will
then be defined. When the file is #included again, since the macro is
defined, it will not be processed (at least the part up until the
corresponding #endif). This prevents headers from being included multiple
times in one translation unit which can cause compile-time errors. Since
the only purpose of the macro is to test it's existence, there is no need
to provide any substitution text.
Casanova...


Rob Gamble

Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.