473,401 Members | 2,127 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,401 software developers and data experts.

Concatenating strings using macros

Can someone tell me what is wrong here ?

Expand|Select|Wrap|Line Numbers
  1. #define LOG_MACRO(format,args...) printf(format,args)
  2.  
  3. #define TEST_MACRO(__arg1, __arg2, __format, args...) LOG_MACRO("ARG1: %s, ARG2 : %s" ## __format, ##args)
  4.  
  5. char* arg1 = "test";
  6. char* arg2 = "test";
  7. TEST_MACRO(arg1,arg2,"Testing Macro %s","foo");

error: pasting ""ARG1: %s, ARG2 : %s"" and ""Testing Macro %s"" does not give a valid preprocessing token
Mar 23 '13 #1
4 1550
weaknessforcats
9,208 Expert Mod 8TB
I m not a macro expoert but the args... looks incorrect. Remove the ...

Ellipsis arguments work in printf because they are coded in the function. There is nothing in your macro support va_arg.
Mar 24 '13 #2
I only need to paste two strings to make it look like one string so that it goes as one argument to one function. args... is not the issue here. Even If remove it I get the same error.
Mar 24 '13 #3
donbock
2,426 Expert 2GB
What compiler are you using?
Standard support for variable arguments in macros was not available until C99, but it was available as a nonstandard extension in some compilers before that. The first thing to determine is whether your compiler follows the new Standard or if it has its own idiosyncratic way.
Mar 25 '13 #4
Banfa
9,065 Expert Mod 8TB
The error is in this bit

"ARG1: %s, ARG2 : %s" ## __format

The first part is a string and __format is also a string, they do not need to be concatenated with ## the compiler automatically concatenates consecutive strings.

Also you are note using __arg1 and __arg2

These appear to be strings which probably means you want your macro to be

Expand|Select|Wrap|Line Numbers
  1. #define TEST_MACRO(__arg1, __arg2, __format, args...) LOG_MACRO("ARG1: "%s, ARG2 : %s" __format, __arg1, __arg2, ##args)
  2.  
If you are using the gcc extension that removes the final , if args is empty.
Mar 25 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Juan | last post by:
Does any one know if there are reported bugs when concatenating strings? When debugging each variable has the correct value but when I try to concatenate them some values are missing (I canīt see...
4
by: FB's .NET Dev PC | last post by:
Interesting note, the code below as is will attempt to cast what is clearly indicated as a string into a double. This is becuase the use of + as a concatenation operator. The error message...
6
by: Hennie7863 | last post by:
Hi, I have table which has the following values : ID SEQ Text 1 1 A 2 1 B 3 2 C 4 2 D 5 2 E
4
by: lindiwemaduna | last post by:
I want to concatenate values of two text boxes into one string but these should be separated by a space in the database table. i have tried all the following but twas not successful: Dim fullName...
21
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to...
3
by: Big Brother | last post by:
I've been thinking about the seemingly simple task of writing a va_arg-type function to concatenate arbitarily many strings. My first thoughts violated the following principles: 1) never...
5
by: 2di | last post by:
Hi every one, I got this problem, i need to create classes in c++ by using macros. Thats what i want: #define createObject(type) type a; main(){ string className = "int"; ...
4
by: clinisbut | last post by:
I'm not sure if this is the right group, but I didn't found any other more appropiate to post my problem. I'm trying to concatenate chars using the Glib library and I'm getting strange...
13
by: sinbad | last post by:
hi, how to concatenate a "hash defined" constant value to another "hash defined" constant string. For example #define ABC 100 #define MYSTR "The value of ABC is" Now i need a string that...
6
by: nicolenwn | last post by:
Hi everyone(: I'm having trouble creating pivot tables using macros. First i tried recording it then running the exact same thing. It worked fine the first time but a week later when i tried...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.