473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Macro without string to substitute

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
1 2105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: jjleto | last post by:
I have a C program that uses in some parts macros with # and ## like in: #define GET_FUNC_DECL(name) char *get##name(); #define GET_FUNC_IMPL(name) char *get##name() { /* some stuff */; return...
5
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all",...
6
by: Casanova | last post by:
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...
6
by: Roman Mashak | last post by:
Hello, All! I would like to use this macro to substitute type of variable, but it doesn't work by now: typedef enum table_type_e { INT, FLOAT, DOUBLE } table_type_t;
8
by: David | last post by:
Hi, I am using header file for driver so Can I define macro to call Kernel function ? What are the generatl rules for defining macro. - David
28
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something...
1
by: todWulff | last post by:
Good day folks. Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.