Please let me know how this macro works and please provide an example
for, how to call it in my main() function.
#include <stdio.h>
#define MY_ENUM_BEGIN(etype) typedef enum etype##e {
#define MY_ENUM_END(etype) } etype##t
Thanks in advance
Vishal. 3 1250
Vish wrote: Please let me know how this macro works and please provide an example for, how to call it in my main() function.
#include <stdio.h> #define MY_ENUM_BEGIN(etype) typedef enum etype##e { #define MY_ENUM_END(etype) } etype##t
A macro basically gets translated into code before compilation. The
above macro will work something like this:
MY_ENUM_BEGIN(my_enum_type)
zero,
one,
two,
five = 5
MY_ENUM_END(my_enum_type);
This will be translated into:
typedef enum my_enum_typee {
zero,
one,
two,
five = 5
} my_enum_typet;
--
bjrnove
Le 15/06/2005 15:23, dans 11**********************@g43g2000cwa.googlegroups. com, «*bjrnove*»
<bj*****@gmail.com> a écrit*: Vish wrote: Please let me know how this macro works and please provide an example for, how to call it in my main() function.
#include <stdio.h> #define MY_ENUM_BEGIN(etype) typedef enum etype##e { #define MY_ENUM_END(etype) } etype##t
A macro basically gets translated into code before compilation. The above macro will work something like this:
MY_ENUM_BEGIN(my_enum_type) zero, one, two, five = 5 MY_ENUM_END(my_enum_type);
This will be translated into:
typedef enum my_enum_typee { zero, one, two, five = 5 } my_enum_typet;
Wow ! I prefer the second one. Just for clarity's sake :-)
Vish wrote: Please let me know how this macro works and please provide an example for, how to call it in my main() function.
#include <stdio.h> #define MY_ENUM_BEGIN(etype) typedef enum etype##e { #define MY_ENUM_END(etype) } etype##t
During the preprocessing phase, all occurrences of MY_ENUM_BEGIN(x) are
replaced with the text typedef enum xe { (the ## operator in the
preprocessor merges tokens), and all occurrences of MY_ENUM_END(x) are
replaced with the text } xt. So in your main() function, you'd write
MY_ENUM_BEGIN(colors)
blue,
red,
green,
cyan,
magenta,
yellow,
white,
black
MY_ENUM_END(colors);
which, after preprocessing, would be replaced with
typedef enum colorse {
blue,
red,
green,
cyan,
magenta,
yellow,
white,
black
} colorst;
This is an example of preprocessor abuse, adds zero clarity or
readability to the code, and is bad style IMO. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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: Cowboy \(Gregory A. Beamer\) |
last post by:
There seems to be a lot of confusion on the versions of Visual Studio 2005.
My latest blog entry covers the different versions:
Main URL:...
|
by: Pete |
last post by:
In Access 95/97 I used to be able to create pull down menus (File,Edit
...) from a macro. It seems there used to be some wizard for that.
However in Access 2000 it seems you have to build your...
|
by: Newbie_sw2003 |
last post by:
Where should I use them?
I am giving you my understandings. Please correct me if I am wrong:
MACRO:
e.g.:#define ref-name 99
The code is substituted by the MACRO ref-name. So no overhead....
|
by: Alexander Ulyanov |
last post by:
Hi all.
Is it possible to pass the whole blocks of code (possibly including
" and ,) as macro parameters?
I want to do something like:
MACRO(FOO, "Foo",
"return "Foobar";",
"foo();...
|
by: Affan Syed |
last post by:
Hi,
I have done a lot of user space coding in C, which doesnt really need me to
understand the following MACRO:
#define UARTOutput(__x,__y,__args...) do { \
static char __s PROGMEM = __y; \
if...
|
by: Sean |
last post by:
Hi, all - I am having trouble running a macro in Access 2000. In an
action within the macro, it is set up to import data from an excel
file. When I try to run it, I get an error message:
The...
|
by: tonyjeffs2 |
last post by:
//int _tmain(int argc, _TCHAR* argv) // main for windows
int main(int argc, char *argv) // ... or main
{
cout <<argv<<endl;
return 0;
}
//run at command line:...
|
by: ericjohnson |
last post by:
I've got a macro that has already been written for an Excel spreadsheet used for estimating at work. I know enough VB to write very basic macros, but I cannot understand the logic and purpose behind...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |