Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15072 > unrolled thread
| Started by | thomas <freshthomas@gmail.com> |
|---|---|
| First post | 2012-03-27 00:29 -0700 |
| Last post | 2012-03-27 18:00 -0700 |
| Articles | 16 — 7 participants |
Back to article view | Back to comp.lang.c++
macro definition for different compile configurations thomas <freshthomas@gmail.com> - 2012-03-27 00:29 -0700
Re: macro definition for different compile configurations Victor Bazarov <v.bazarov@comcast.invalid> - 2012-03-27 07:58 -0400
Re: macro definition for different compile configurations thomas <freshthomas@gmail.com> - 2012-03-27 06:44 -0700
Re: macro definition for different compile configurations Qi <no@no.com> - 2012-03-27 21:53 +0800
Re: macro definition for different compile configurations Juha Nieminen <nospam@thanks.invalid> - 2012-03-27 17:31 +0000
Re: macro definition for different compile configurations thomas <freshthomas@gmail.com> - 2012-03-27 07:05 -0700
Re: macro definition for different compile configurations Geoff <geoff@invalid.invalid> - 2012-03-27 09:49 -0700
Re: macro definition for different compile configurations Stuart Redmann <DerTopper@web.de> - 2012-03-27 11:27 -0700
Re: macro definition for different compile configurations Geoff <geoff@invalid.invalid> - 2012-03-27 11:46 -0700
Re: macro definition for different compile configurations Stuart Redmann <DerTopper@web.de> - 2012-03-27 12:39 -0700
Re: macro definition for different compile configurations Ian Collins <ian-news@hotmail.com> - 2012-03-28 08:49 +1300
Re: macro definition for different compile configurations Stuart Redmann <DerTopper@web.de> - 2012-03-27 12:58 -0700
Re: macro definition for different compile configurations Geoff <geoff@invalid.invalid> - 2012-03-27 15:50 -0700
Re: macro definition for different compile configurations Juha Nieminen <nospam@thanks.invalid> - 2012-03-28 08:14 +0000
Re: macro definition for different compile configurations Stuart Redmann <DerTopper@web.de> - 2012-03-28 07:30 -0700
Re: macro definition for different compile configurations thomas <freshthomas@gmail.com> - 2012-03-27 18:00 -0700
| From | thomas <freshthomas@gmail.com> |
|---|---|
| Date | 2012-03-27 00:29 -0700 |
| Subject | macro definition for different compile configurations |
| Message-ID | <26170974.62.1332833351847.JavaMail.geo-discussion-forums@ynel5> |
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
[toc] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2012-03-27 07:58 -0400 |
| Message-ID | <jksa0h$aa4$1@dont-email.me> |
| In reply to | #15072 |
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
[toc] | [prev] | [next] | [standalone]
| From | thomas <freshthomas@gmail.com> |
|---|---|
| Date | 2012-03-27 06:44 -0700 |
| Message-ID | <2199915.429.1332855873157.JavaMail.geo-discussion-forums@ynlw24> |
| In reply to | #15072 |
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
[toc] | [prev] | [next] | [standalone]
| From | Qi <no@no.com> |
|---|---|
| Date | 2012-03-27 21:53 +0800 |
| Message-ID | <jksgq6$cl5$1@speranza.aioe.org> |
| In reply to | #15075 |
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
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2012-03-27 17:31 +0000 |
| Message-ID | <4f71f95e$0$4354$7b1e8fa0@news.nbl.fi> |
| In reply to | #15076 |
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.)
[toc] | [prev] | [next] | [standalone]
| From | thomas <freshthomas@gmail.com> |
|---|---|
| Date | 2012-03-27 07:05 -0700 |
| Message-ID | <29708976.1032.1332857135546.JavaMail.geo-discussion-forums@ynim7> |
| In reply to | #15072 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2012-03-27 09:49 -0700 |
| Message-ID | <oer3n79jhgetu03kpaoa7tpi59pu68k7u9@4ax.com> |
| In reply to | #15077 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Stuart Redmann <DerTopper@web.de> |
|---|---|
| Date | 2012-03-27 11:27 -0700 |
| Message-ID | <2b036b7e-a9c8-48a9-8907-3c181f633d98@l18g2000vbx.googlegroups.com> |
| In reply to | #15078 |
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
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2012-03-27 11:46 -0700 |
| Message-ID | <ug24n7hcdnsf99fecqfh6fvds2c8bq1mcd@4ax.com> |
| In reply to | #15080 |
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?
[toc] | [prev] | [next] | [standalone]
| From | Stuart Redmann <DerTopper@web.de> |
|---|---|
| Date | 2012-03-27 12:39 -0700 |
| Message-ID | <7ea9dbcd-e671-490a-a2b0-63ef6637c558@v22g2000vby.googlegroups.com> |
| In reply to | #15083 |
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
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2012-03-28 08:49 +1300 |
| Message-ID | <9teju2Fe0nU5@mid.individual.net> |
| In reply to | #15085 |
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
[toc] | [prev] | [next] | [standalone]
| From | Stuart Redmann <DerTopper@web.de> |
|---|---|
| Date | 2012-03-27 12:58 -0700 |
| Message-ID | <75be37f7-5385-4d7a-8c82-44d1707c0631@w1g2000vbx.googlegroups.com> |
| In reply to | #15086 |
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
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2012-03-27 15:50 -0700 |
| Message-ID | <6pf4n7l1757fpqqc84tpbuos7jqusa6qft@4ax.com> |
| In reply to | #15088 |
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."
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2012-03-28 08:14 +0000 |
| Message-ID | <4f72c85e$0$4386$7b1e8fa0@news.nbl.fi> |
| In reply to | #15083 |
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."
[toc] | [prev] | [next] | [standalone]
| From | Stuart Redmann <DerTopper@web.de> |
|---|---|
| Date | 2012-03-28 07:30 -0700 |
| Message-ID | <d403a94b-7b7a-4849-b485-b161f0f5475d@p13g2000yqd.googlegroups.com> |
| In reply to | #15090 |
On 28 Mrz., Juha Nieminen wrote: > Geoff <ge...@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." The clearest so far. I'm still thinking about which kind of trophy I should award. Were this an MSDN forum, I could give you a positive vote, but I guess that this topic would never have been approved by MS. Regards, Stuart
[toc] | [prev] | [next] | [standalone]
| From | thomas <freshthomas@gmail.com> |
|---|---|
| Date | 2012-03-27 18:00 -0700 |
| Message-ID | <23874159.110.1332896453592.JavaMail.geo-discussion-forums@vbai14> |
| In reply to | #15078 |
On Wednesday, March 28, 2012 12:49:09 AM UTC+8, Geoff wrote:
> 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.
Well, I know that overloading can make the same function name work for different parameter list. But I want to see different functions for different configurations. If I define both, it's confusing which is used when. Sometimes the parameter in difference is just meaningness in some configurations.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web