Hi,
I'm trying to define a macro that calls a log function:
#define LOG(level, device, pcString, args ...) if (level < SERIAL_LOG_LEVEL) _log(device, pcString, ## args)
void _log (unsigned char device, const char *pcString, ...);
I want the macro to accept multiple args with "..." but the compiler didn't like it. It works fine if i simply do.
#define LOG(level, device, pcString, args ) if (level < SERIAL_LOG_LEVEL) _log(device, pcString, ## args)
and when i call
d = 0;
LOG(1, 0, "hello world %d", d);
What am i doing wrong?
Thank you for your help.
Regards,
John
6 2682
I think you miss the, after the args in the #define.
Raghu
I think you miss the, after the args in the #define.
Raghu
Ok, that works with 1 or more arguments, but if i do
LOG(1, 0, "hello world");
compiler says too few argument in macro.
I'm using IAR by the way.
Thank you.
Ok, that works with 1 or more arguments, but if i do
LOG(1, 0, "hello world");
compiler says too few argument in macro.
I'm using IAR by the way.
Thank you.
Since you have specified 4 args followed by elipsis it is expecting 4 arguments atleast.
Then you shuld change the Macro....
Raghu
Since you have specified 4 args followed by elipsis it is expecting 4 arguments atleast.
Then you shuld change the Macro....
Raghu
Shouldn't the "..." allow 0 or more arguments? so that the below should accept 3 arguments or more.
#define LOG(level, device, pcString, ...) \
if (level < SERIAL_LOG_LEVEL) _log(device, pcString, ## __VA_ARGS__)
Shouldn't it?
Thank you.
Shouldn't the "..." allow 0 or more arguments? so that the below should accept 3 arguments or more.
#define LOG(level, device, pcString, ...) \
if (level < SERIAL_LOG_LEVEL) _log(device, pcString, ## __VA_ARGS__)
Shouldn't it?
Thank you.
This is what the C99 Standard says about it:
[#12] If there is a ... in the identifier-list in the macro
definition, then the trailing arguments, including any
separating comma preprocessing tokens, are merged to form a
single item: the variable arguments. The number of arguments
so combined is such that, following merger, the number of
arguments is one more than the number of parameters in the
macro definition (excluding the ...).
kind regards,
Jos
This is what the C99 Standard says about it:
kind regards,
Jos
Thank you very much, I understand what I'm doing wrong now.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: s |
last post by:
Can I do this:
#define MYSTRING "ABC"
..
..
..
char mychar = MYSTRING;
..
..
..
|
by: Bolin |
last post by:
I am using a macro to define template functions that look the same
except for a type. However when the return type it a template class
with several template arguments (say, A<T1, T2>) then the...
|
by: Bryan Parkoff |
last post by:
"#define" can only be inside the global scope before main() function.
"#if" can be tested after "#define" is executed. The problem is that
"#define" can't be inside main() function. I do not wish...
|
by: BQ |
last post by:
Hello
Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is
greater than 35, it returns 56, if not, 20.
I would like that at compile time, not at run time.
...
|
by: marcwentink |
last post by:
Dear people,
The code below is compiling:
#define BUF_SZ 16383
.....
strcat(ConnectString, "Content-Length: BUF_SZ\n");
but it does not work since it give me:
|
by: Mohammad Omer Nasir |
last post by:
I was read Linux kernel code in which I saw few define
macro defines in functions. The snap of the function is following and
file name "err_ev6.c".
static int
ev6_parse_cbox(u64 c_addr, u64...
|
by: anirbid.banerjee |
last post by:
Hi,
I need to write a macro which would have a lot many conditional
#ifdef ... #endif blocks in it.
#define _xx_macro (x) {
... \
... \ /* some code (); */
#ifdef _SOME_STMT \
... \
... \
|
by: raghu |
last post by:
Hello
I have a doubt plz clarify that
#ifndef SYSTEM_H
#define SYSTEM_H
what will be the value of SYATEM_H after this #define statement and
before that statement.
Thanking you all
Bye
|
by: venkat |
last post by:
I have come across some preprossor statements, such as
#define PPTR_int
#define PPTR_str
#define DDAR_baddr &
#define DDAR_caddr &
What do they mean, but when i compile the code with these...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
| |