Hi,
I'm stucked by something appears really simple at first sight.
I have a function definition with different parameter list in different compile configurations. for example.
--------------------------
CONF1:
int f(int x, int y){}
int g(int x){}
CONF2:
int f(int y){}
int g(){}
----------------------------
I'm trying to define some marco like
#if CONF1
#define PARAM(list) int x, list
#elseif CONF2
#define PARAM(list) list
#endif
But it cannot work for func g() definition in CONF1 since a "," is appended unexpectedly.
It seems to be really simple, but I am now a little dumb how to define one and solve it elegantly.
thanks.
tom
|
|
0
|
|
|
|
Reply
|
freshthomas (139)
|
3/27/2012 7:29:11 AM |
|
On 3/27/2012 3:29 AM, thomas wrote:
> Hi,
> I'm stucked by something appears really simple at first sight.
>
> I have a function definition with different parameter list in different compile configurations. for example.
>
> --------------------------
> CONF1:
> int f(int x, int y){}
> int g(int x){}
>
> CONF2:
> int f(int y){}
> int g(){}
Why don't your functions declared returning a value return a value? Are
those supposed to be definitions or declarations?
You *do* know that in C++ you're allowed to have functions with the same
name and different argument list, right? That's called "overloading".
You *can* declare/define your 'f' and 'g' all in the same scope.
> ----------------------------
> I'm trying to define some marco like
>
> #if CONF1
> #define PARAM(list) int x, list
> #elseif CONF2
> #define PARAM(list) list
> #endif
And use it HOW? To achieve WHAT?
> But it cannot work for func g() definition in CONF1 since a "," is appended unexpectedly.
"Cannot work" for what?
> It seems to be really simple, but I am now a little dumb how to define one and solve it elegantly.
What exactly are you *trying to do*? You're stating that your solution
is not working, but what is *the problem* that you're trying to solve?
(And please don't tell us that the problem is that the solution is not
working)
V
--
I do not respond to top-posted replies, please don't ask
|
|
0
|
|
|
|
Reply
|
v.bazarov (788)
|
3/27/2012 11:58:08 AM
|
|
Ok...
#ifdef _A_
#define PARAM_WITH_COMMA int x,
#defien PARAM_NO_COMMA int x
#else
#define PARAM_WITH_COMMA
#define PARAM_NO_COMMA
#endif
And I have two versions of following functions
#ifdef _A_
int f(int x, int y);
int f(int x);
#else
int f(int y);
int f();
#endif
And I can write the two versions of the functions with the following declaration.
int f(PARAM_WITH_COMMA int y);
int f(PARAM_NO_COMMA);
In short I want to make my code neat and easy to read, that's to say, fewer "#ifdef" like stuff.
So I'm trying to write some macros to shorten some word usage.
I just gave an example above using two marco definitions.
Can I use just one macro to achieve the same thing?
On Tuesday, March 27, 2012 3:29:11 PM UTC+8, thomas wrote:
> Hi,
> I'm stucked by something appears really simple at first sight.
>
> I have a function definition with different parameter list in different compile configurations. for example.
>
> --------------------------
> CONF1:
> int f(int x, int y){}
> int g(int x){}
>
> CONF2:
> int f(int y){}
> int g(){}
> ----------------------------
> I'm trying to define some marco like
>
> #if CONF1
> #define PARAM(list) int x, list
> #elseif CONF2
> #define PARAM(list) list
> #endif
>
> But it cannot work for func g() definition in CONF1 since a "," is appended unexpectedly.
>
> It seems to be really simple, but I am now a little dumb how to define one and solve it elegantly.
>
> thanks.
>
> tom
|
|
0
|
|
|
|
Reply
|
freshthomas (139)
|
3/27/2012 1:44:33 PM
|
|
On 2012-3-27 21:44, thomas wrote:
> Ok...
Please top quote. And keep your line width within 76
characters.
> And I can write the two versions of the functions with the following declaration.
> int f(PARAM_WITH_COMMA int y);
> int f(PARAM_NO_COMMA);
>
> In short I want to make my code neat and easy to read, that's to say, fewer "#ifdef" like stuff.
>
> So I'm trying to write some macros to shorten some word usage.
Using macro is neither neat nor easy to read.
Whenever you can avoid macros, just avoid them.
You are using C++. C++ can do most stuff that macro can do.
When you want to write a macro, rethink again.
> I just gave an example above using two marco definitions.
>
> Can I use just one macro to achieve the same thing?
There is comma_if in Boost library. You may check Boost
preprocessor library.
--
WQ
|
|
0
|
|
|
|
Reply
|
no357 (668)
|
3/27/2012 1:53:57 PM
|
|
On Tuesday, March 27, 2012 3:29:11 PM UTC+8, thomas wrote:
> Hi,
> I'm stucked by something appears really simple at first sight.
>
> I have a function definition with different parameter list in different compile configurations. for example.
>
> --------------------------
> CONF1:
> int f(int x, int y){}
> int g(int x){}
>
> CONF2:
> int f(int y){}
> int g(){}
> ----------------------------
> I'm trying to define some marco like
>
> #if CONF1
> #define PARAM(list) int x, list
> #elseif CONF2
> #define PARAM(list) list
> #endif
>
> But it cannot work for func g() definition in CONF1 since a "," is appended unexpectedly.
>
> It seems to be really simple, but I am now a little dumb how to define one and solve it elegantly.
>
> thanks.
>
> tom
Seems that you don't understand what I am talking about, just judging by some keyword mentioned.
|
|
0
|
|
|
|
Reply
|
freshthomas (139)
|
3/27/2012 2:05:35 PM
|
|
On Tue, 27 Mar 2012 07:05:35 -0700 (PDT), thomas
<freshthomas@gmail.com> wrote:
>On Tuesday, March 27, 2012 3:29:11 PM UTC+8, thomas wrote:
>> Hi,
>> I'm stucked by something appears really simple at first sight.
>>
>
>Seems that you don't understand what I am talking about, just judging by some keyword mentioned.
Try replying to the people your post is intended to reply to instead
of yourself.
You have not clearly stated your problem.
If you are coding C++ you do not need to write macros to define your
functions using compile time switches. You can simply define your
functions simultaneously in the same scope and let the compiler choose
which overloaded function to use based on the function call.
Defining:
int f(int x, int y){}
int f(int x){}
int f(){}
Calling:
i = f(x,y);
i = f(x);
i = f();
The compiler will choose the proper function that matches the
arguments in the function call.
|
|
0
|
|
|
|
Reply
|
geoff745 (361)
|
3/27/2012 4:49:09 PM
|
|
Qi <no@no.com> wrote:
> C++ can do most stuff that macro can do.
Not everything, though. For instance, there's a reason why assert()
is still a macro in C++. (Because it typically prints the file name
and line number where the assertion failed, plus the expression that
failed, that's basically impossible to achieve without a preprocessor
macro. Even if there was a way to get the line number otherwise (which
there isn't), you still couldn't stringify the expression without the
preprocessor.)
|
|
0
|
|
|
|
Reply
|
nospam270 (2853)
|
3/27/2012 5:31:10 PM
|
|
On March, 27th, Geoff wrote:
[snip]
> Try replying to the people your post is intended to reply to instead
> of yourself.
[snip]
Gosh, it took me almost one minute to figure out what your sentence
actually means. I take it from your profile that you are a native
speaker, so I assume that such sentences are nothing strange. Still, I
wonder whether this is considered good English or not. A comma would
be a great hint for non-native speakers, but I guess that your
sentence is grammatically correct.
Regards,
Stuart
|
|
0
|
|
|
|
Reply
|
DerTopper (387)
|
3/27/2012 6:27:14 PM
|
|
On Tue, 27 Mar 2012 11:27:14 -0700 (PDT), Stuart Redmann
<DerTopper@web.de> wrote:
>On March, 27th, Geoff wrote:
>
>[snip]
>
>> Try replying to the people your post is intended to reply to instead
>> of yourself.
>
>[snip]
>
>Gosh, it took me almost one minute to figure out what your sentence
>actually means. I take it from your profile that you are a native
>speaker, so I assume that such sentences are nothing strange. Still, I
>wonder whether this is considered good English or not. A comma would
>be a great hint for non-native speakers, but I guess that your
>sentence is grammatically correct.
>
Stuart,
I pumped it through LibreOffice just to see if it would flag the
grammar, it did not.
However, I suppose it could have been phrased better and more
formally:
"You should reply and quote the people to whom you are intending to
reply, rather than replying to yourself."
Better?
|
|
0
|
|
|
|
Reply
|
geoff745 (361)
|
3/27/2012 6:46:52 PM
|
|
On 27 Mrz., 20:46, Geoff <ge...@invalid.invalid> wrote:
> On Tue, 27 Mar 2012 11:27:14 -0700 (PDT), Stuart Redmann
>
>
>
>
>
>
>
>
>
> <DerTop...@web.de> wrote:
> >On March, 27th, Geoff wrote:
>
> >[snip]
>
> >> Try replying to the people your post is intended to reply to instead
> >> of yourself.
>
> >[snip]
>
> >Gosh, it took me almost one minute to figure out what your sentence
> >actually means. I take it from your profile that you are a native
> >speaker, so I assume that such sentences are nothing strange. Still, I
> >wonder whether this is considered good English or not. A comma would
> >be a great hint for non-native speakers, but I guess that your
> >sentence is grammatically correct.
>
> Stuart,
> I pumped it through LibreOffice just to see if it would flag the
> grammar, it did not.
>
> However, I suppose it could have been phrased better and more
> formally:
>
> "You should reply and quote the people to whom you are intending to
> reply, rather than replying to yourself."
>
> Better?
Still looks weird to me.
"You should reply to the people to whom you are intending to reply,
rather than replying to yourself." looks somewhat better, even though
it may not be grammatically correct. Besides, it does not contain the
quoting part. Maybe like this:"You should reply to and quote the
people to whom you are intending to reply, rather than replying to
yourself."
Would that be OK?
Thanks,
Stuart
|
|
0
|
|
|
|
Reply
|
DerTopper (387)
|
3/27/2012 7:39:39 PM
|
|
On 03/28/12 08:39 AM, Stuart Redmann wrote:
>
> "You should reply to the people to whom you are intending to reply,
> rather than replying to yourself." looks somewhat better, even though
> it may not be grammatically correct. Besides, it does not contain the
> quoting part. Maybe like this:"You should reply to and quote the
> people to whom you are intending to reply, rather than replying to
> yourself."
>
> Would that be OK?
Or simply direct the OP to
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4
--
Ian Collins
|
|
0
|
|
|
|
Reply
|
ian-news (9878)
|
3/27/2012 7:49:22 PM
|
|
On 27 Mrz., Ian Collins wrote:
[snip]
> Or simply direct the OP to
>
> http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4
Acknowledged. However, I was intending to improve my English.
In that matter, I'd rather say
"You should reply to the people whom you are intending to reply to,
[...]"
than
"You should reply to the people to whom you are intending to reply,
[...]"
Would that still be correct?
Regards,
Stuart
|
|
0
|
|
|
|
Reply
|
DerTopper (387)
|
3/27/2012 7:58:21 PM
|
|
On Tue, 27 Mar 2012 12:58:21 -0700 (PDT), Stuart Redmann
<DerTopper@web.de> wrote:
>On 27 Mrz., Ian Collins wrote:
>
>[snip]
>
>> Or simply direct the OP to
>>
>> http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4
>
>Acknowledged. However, I was intending to improve my English.
>
>
>
>In that matter, I'd rather say
>"You should reply to the people whom you are intending to reply to,
>[...]"
>than
>"You should reply to the people to whom you are intending to reply,
>[...]"
>
>Would that still be correct?
>
>Regards,
>Stuart
I have to say the latter is more correct. putting the 'to' after
'reply' is splitting the infinitive. The 'to' belongs to 'whom' and
not to the verb 'reply'. But it is also more formal. You were correct
when you called me out on the 'to reply to'. You should probably also
discard the 'to the people'.
"You should reply to whom you are intending to reply, rather than
replying to yourself."
|
|
0
|
|
|
|
Reply
|
geoff745 (361)
|
3/27/2012 10:50:49 PM
|
|
Geoff <geoff@invalid.invalid> wrote:
> "You should reply and quote the people to whom you are intending to
> reply, rather than replying to yourself."
"Rather than replying to yourself, you should reply to the people you
are intending to reply. It makes it clearer who you are talking to."
|
|
0
|
|
|
|
Reply
|
nospam270 (2853)
|
3/28/2012 8:14:22 AM
|
|
|
13 Replies
50 Views
(page loaded in 0.148 seconds)
Similiar Articles: `ifdef inside a macro - comp.lang.verilog... 42044]: Compiler directive `ifdef is present inside macro definition. Warning: [42044]: Compiler ... be safer to turn the whole thing inside-out, with two different ... Compiler warnings assoc. with 'fileno' being deprecated on Windows ...... MACHINE and OPERATING SYSTEM, if different ... For my configuration, I am most concerned with ... win32*.h file, changing the definition of the ACE_FILENO_EQUIVALENT macro to ... Explanation needed for const int "error: variably modified ... at ...... grafted on top of another language, with radically different syntax and semantics. A macro definition is ... words "const" to mean read-only and "constant" to mean compile ... can't get real path - comp.unix.solaris... to patch a compiler ... and found a macro definition ... itself in a different error message IIRC. > I got. I dived into opensolaris sources and found a macro > definition ... Merlin under ProDOS - comp.sys.apple2.programmer... internals, like memory allocation and configuration for ... they can do, but all can "regurgitate" a macro definition in ... the program that are closely related, but different. class definition containing member of own type - comp.lang.c++ ...So the compiler knows everything it needs to ... lang.c++.moderated... units "see" different versions of a class definition ... ... Online Dictionary ..... group, or configuration ... Fortran 95 equivalent of read(..., POS=...) - comp.lang.fortran ...... 95" is not a sufficient description of a compiler. There are different ... half-complete stream access, because the configuration for the software set the HAVE_STREAM macro. Need a FORTRAN compiler for Win7 (or XP) - comp.lang.fortran ...... back to 1964, and would like to compile ... various compilers. > > OW is no different in that regard; it is a F77-compliant compiler ... constants, when a little re-definition to ... Difference between passing a number and a variable to a subroutine ...For example, the code below will not compile with the ... in the error message - they are quite >> different. ... Pass a variable as a macro parameter. - comp.soft-sys ... Commercial Fortran Compilers - comp.lang.fortran... for a single copy of a commercial* Fortran compiler to ... beautifully, and is fairly >portable across different ... this was related to trigraphs in C, or cpp macro ... extern typedef struct - comp.lang.cThis will already trip up the compiler since 'object' is ... So you put the definition of the variable with- out that ... Now I look at 6.10.3 Macro replacement, item 2 "An ... Neatest way to get the end pointer? - comp.lang.cAssigning a compile-time 0 to a pointer type is ... while(p > s) or > something similar) That is different ... with the length calculation encapsulated in a macro definition ... size of a derived type containing pointers... - comp.lang.fortran ...C has the preprocessor macro CHAR_BIT indicating ... of executables, but that's not the main definition ... the same as sizeof(int) but it may be different at the compiler's ... Harvard problem - comp.text.tex... would like to know why is it that if I compile this ... Then, I have approx. 500.000 different vertexs, so I ... it work ok, but I have a small problem with configuration ... Examples of C++ in Safety Critical Systems - comp.lang.c++ ...I guess these folks forgot that their macro ... to the process, although it may depend on our definition ... In a well run team, however, there will be different ... /define (Preprocessor Definition) (C# Compiler Options)... directive in the source file removes the definition or the compiler ... If you want to create a C++ style macro ... and TRACE constants can be set in any configuration ... Predefined Macros (C/C++)The compiler recognizes predefined ANSI C macros and the ... Macro Description __DATE__. The ... Future compilers will emit a different value to reflect ... 7/14/2012 6:34:08 AM
|