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... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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",...
|
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...
|
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;
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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
|
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...
|
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...
| |