473,394 Members | 1,965 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,394 software developers and data experts.

preprocessing issues

Hello,
I would like to know if there is some preprocessing trick available on
gcc that could expand something like:

debug(a)
debug(x,y, z)

as:

debug_a();

debug_x();
debug_y();
debug_z();

to help me debug many vars of different type.
Thanks,
Gaetano

Jul 16 '07 #1
4 1182
ga***********@yahoo.it wrote:
Hello,
I would like to know if there is some preprocessing trick available on
gcc that could expand something like:

debug(a)
debug(x,y, z)

as:

debug_a();

debug_x();
debug_y();
debug_z();

to help me debug many vars of different type.
Thanks,
Gaetano
You can't have a variable number of parameters (except when using "...")
in a macro.

So :
#define debug1(p1) debug_##p1##();
#define debug2(p1, p2) debug_##p1##(); debug_##p2##();
#define debug3(p1, p2, p3) debug_##p1##(); debug_##p2##(); debug_##p3##();

This is the only solution in C99, but maybe there is some GNU extensions
that I don't know.
Jul 16 '07 #2
On 16 juil, 16:16, gaetanoort...@yahoo.it wrote:
Hello,
I would like to know if there is some preprocessing trick available on
gcc that could expand something like:

debug(a)
debug(x,y, z)

as:

debug_a();

debug_x();
debug_y();
debug_z();

to help me debug many vars of different type.
Thanks,
C99 allows to write such macro, no needs for gcc tricks.

Using the COS macros from:

http://cos.cvs.sourceforge.net/cos/COS/src/cos/fpp/

you can define the macro debug as (tested):

#define debug(...) FPP_SEP(FPP_MAP((__VA_ARGS__),debug_))
#define debug_(a) FPP_CAT(debug_,a)();

where FPP_SEP, FPP_MAP and FPP_CAT are macros available from fpp/
list.h

debug(a) -> debug_a();
debug(x,y,z) -> debug_x(); debug_y(); debug_z();

Other preprocessor libraries like Chaos can also be used instead of
COS fpp.

a+, ld.
Jul 16 '07 #3
Laurent Deniau wrote:
C99 allows to write such macro, no needs for gcc tricks.

Using the COS macros from:

http://cos.cvs.sourceforge.net/cos/COS/src/cos/fpp/
Thank you for the information!!!

For my own education, I've tried to understand your macros.

Here is what I've understood :

#define count_args(...) get_nb_args(__VA_ARGS__, 3, 2, 1)
#define get_nb_args(pad1, pad2, pad3, n, ...) n

#define debug(...) debug_(count_args(__VA_ARGS__), __VA_ARGS__)

#define debug_(a, ...) debug##a(__VA_ARGS__)

#define debug1(a) debug_##a()
#define debug2(a, b) debug1(a); debug_##b()
#define debug3(a, b, c) debug2(a, b); debug_##c()

I've removed all the generic code to make it shorter and to work only in
this specific case.
It seems to work, but I've not carefully tested it in all situations.
Jul 16 '07 #4
Thanks

Jul 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ron | last post by:
The C++ standard ISO/IEC 14882 specifies pp-numbers as follow: pp-number: digit .digit pp-number digit pp-number nondigit pp-number e sign pp-number E sign pp-number .
3
by: Ron | last post by:
Please, consider the following code: const int a = 1; #if a == 1 #define VAR 200 #else #define VAR 100 #endif int main() {
1
by: Alex Sedow | last post by:
Where to get/buy tool for partial preprocessing? 1. What I mean by partial macro preprocessing. This is mode in which almost sources (>99%) is not preprocessed. But some macros (setted by...
12
by: Francois Grieu | last post by:
Can #include safely use a preprocessing token, as in #define HEADERFILE "stdio.h" #include HEADERFILE int main(void) {return printf("Hello, world\n")*0;} TIA, François Grieu
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
3
by: Frodo Baggins | last post by:
Hi All, I have a piece of code (not written by me) that is failing on compile with the error: pasting "xdr_ndmp_connect_open_request" and "," does not give a valid preprocessing token The...
4
by: Henrik Goldman | last post by:
I have an application which compiles on a number of different platforms. Now I'm trying to incorporate an external library which is only available to a subset of the platforms that my application...
5
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing...
40
by: Bill Cunningham | last post by:
I have been thinking about hiding headers from my compiler's preprocessor and allowing others to be shown. I want to use the most used and add others is necessary. Would this be how it is properly...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.