I need to do something like this
#define P1(x) int x##__LINE__ = __LINE__;
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
I mean that the macro should be expanded in this way:
int main(int argc, char* argv[])
{
int a3 = 3;
int a4 = 4;
}
but the code above does not work.
How would you implement it?
Thanks 4 1589 ni*****@googlemail.com wrote:
I need to do something like this
#define P1(x) int x##__LINE__ = __LINE__;
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
I mean that the macro should be expanded in this way:
int main(int argc, char* argv[])
{
int a3 = 3;
int a4 = 4;
}
but the code above does not work.
How would you implement it?
You need a second level of indirection to use the ## :
#define TOGETHER(a,b) a##b
#define P1(x) int TOGETHER(x,__LINE__) = __LINE__
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Oct 27, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
nick...@googlemail.com wrote:
I need to do something like this
#define P1(x) int x##__LINE__ = __LINE__;
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
I mean that the macro should be expanded in this way:
int main(int argc, char* argv[])
{
int a3 = 3;
int a4 = 4;
}
but the code above does not work.
How would you implement it?
You need a second level of indirection to use the ## :
#define TOGETHER(a,b) a##b
#define P1(x) int TOGETHER(x,__LINE__) = __LINE__
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I tried something like this (this is why my macro is called P1: there
was a P2). It looks like it does not work.
I am using VS 2005. The error message at compile time is: error C2374:
'a__LINE__': redefinition...
The code I run is:
#define TOGETHER(a,b) a##b
#define P1(x) int TOGETHER(x,__LINE__) = __LINE__;
int main(int argc, char* argv[])
{
P1(a);
P1(a);
} ni*****@googlemail.com wrote:
On Oct 27, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>nick...@googlemail.com wrote:
>>I need to do something like this
>>#define P1(x) int x##__LINE__ = __LINE__;
>>int main(int argc, char* argv[]) { P1(a); P1(a); }
>>I mean that the macro should be expanded in this way:
>>int main(int argc, char* argv[]) { int a3 = 3; int a4 = 4; }
>>but the code above does not work.
>>How would you implement it?
You need a second level of indirection to use the ## :
#define TOGETHER(a,b) a##b #define P1(x) int TOGETHER(x,__LINE__) = __LINE__
V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask
I tried something like this (this is why my macro is called P1: there
was a P2). It looks like it does not work.
I am using VS 2005. The error message at compile time is: error C2374:
'a__LINE__': redefinition...
The code I run is:
#define TOGETHER(a,b) a##b
#define P1(x) int TOGETHER(x,__LINE__) = __LINE__;
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
Right. Sorry. Another level of indirection is needed:
#define TOGETHER(a,b) a ## b
#define TOGETHER2(a,b) TOGETHER(a,b)
#define P1(x) int TOGETHER2(x,__LINE__) = __LINE__
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
On Oct 27, 6:28 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
nick...@googlemail.com wrote:
On Oct 27, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
nick...@googlemail.com wrote: I need to do something like this
>#define P1(x) int x##__LINE__ = __LINE__;
>int main(int argc, char* argv[]) { P1(a); P1(a); }
>I mean that the macro should be expanded in this way:
>int main(int argc, char* argv[]) { int a3 = 3; int a4 = 4; }
>but the code above does not work.
>How would you implement it?
You need a second level of indirection to use the ## :
#define TOGETHER(a,b) a##b
#define P1(x) int TOGETHER(x,__LINE__) = __LINE__
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
I tried something like this (this is why my macro is called P1: there
was a P2). It looks like it does not work.
I am using VS 2005. The error message at compile time is: error C2374:
'a__LINE__': redefinition...
The code I run is:
#define TOGETHER(a,b) a##b
#define P1(x) int TOGETHER(x,__LINE__) = __LINE__;
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
Right. Sorry. Another level of indirection is needed:
#define TOGETHER(a,b) a ## b
#define TOGETHER2(a,b) TOGETHER(a,b)
#define P1(x) int TOGETHER2(x,__LINE__) = __LINE__
int main(int argc, char* argv[])
{
P1(a);
P1(a);
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Thanks! 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: 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: lasek |
last post by:
Hi...in some posts i've read...something about using macro rather then
function...but difference ??.
Best regards....
|
by: Laurent Deniau |
last post by:
I was playing a bit with the preprocessor of gcc (4.1.1). The following
macros expand to:
#define A(...) __VA_ARGS__
#define B(x,...) __VA_ARGS__
A() -nothing, *no warning*
A(x) -x
...
|
by: Takeadoe |
last post by:
Dear NG,
Can someone assist me with writing the little code that is needed to
run an update table query each time the database is opened? From what
I've been able to glean from this group, the...
|
by: Bill |
last post by:
This database has no forms. I am viewing an Access table in datasheet
view. I'd like to execute a macro to execute a function (using
"runcode"). In the function, I'll reading data from the record...
|
by: =?Utf-8?B?TGV0emRvXzF0?= |
last post by:
I'd like to create a Macro that will sort some raw data, apprx 20k lines,
remove some lines based upon a condition in a certain column. Then copy this
data into a new spreadsheet and sort the ...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
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: 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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
| |