472,114 Members | 1,162 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,114 software developers and data experts.

Macro parameter list

I got a macro like this in my code.
#define DECLARE_SOMEWNDSTRUCTURE(style, nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStruct()\
{\
static SOMEWNDSTRUCT somestruct = {\
style, bits, clrref, icon, tablenum, name, menuname};\
return somestruct ;\
} And I want to be able to do something like this
Have a generic paremeter list...
GENERIC 1,2,3,4,5,6,7
GENERICNAME(name) 1,2,3,4,5,name,7 Which then could be used like this.
DECLARE_SOMEWNDSTRUCTURE(GENERIC)
DECLARE_SOMEWNDSTRUCTURE(GENERICNAME("Jimbo"))

Obviously this doesn't work - warning C4003: not enough actual
parameters for macro...So could anybody explain how something like this
is done?

Mar 23 '06 #1
28 5989

Jack Morgan wrote:
I got a macro like this in my code.

#define DECLARE_SOMEWNDSTRUCTURE(style, nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStruct()\
{\
static SOMEWNDSTRUCT somestruct = {\
style, bits, clrref, icon, tablenum, name, menuname};\
return somestruct ;\
}

And I want to be able to do something like this
Have a generic paremeter list...
GENERIC 1,2,3,4,5,6,7
GENERICNAME(name) 1,2,3,4,5,name,7

Which then could be used like this.
DECLARE_SOMEWNDSTRUCTURE(GENERIC)
DECLARE_SOMEWNDSTRUCTURE(GENERICNAME("Jimbo"))

Obviously this doesn't work - warning C4003: not enough actual
parameters for macro...So could anybody explain how something like this
is done?


Here's an example of how to do it (with some trivial test code; this
has been tested):

#define PRINT3D(a,b,c) do {printf("%d%d%d\n",a,b,c);} while(0)
#define MACROCALL(x,y) x(y)
#define P3DARGS 1,2,3

#include <stdio.h>

int main(void)
{
MACROCALL(PRINT3D,P3DARGS);
return 0;
}

In many preprocessor problems, an extra level of macro expansion is all
that is needed. This shouldn't be too hard to adapt to your code.

Mar 23 '06 #2
* Jack Morgan:
I got a macro like this in my code.
#define DECLARE_SOMEWNDSTRUCTURE(style, nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStruct()\
{\
static SOMEWNDSTRUCT somestruct = {\
style, bits, clrref, icon, tablenum, name, menuname};\
return somestruct ;\
}
And I want to be able to do something like this
Have a generic paremeter list...
GENERIC 1,2,3,4,5,6,7
GENERICNAME(name) 1,2,3,4,5,name,7
Which then could be used like this.
DECLARE_SOMEWNDSTRUCTURE(GENERIC)
DECLARE_SOMEWNDSTRUCTURE(GENERICNAME("Jimbo"))
Obviously this doesn't work - warning C4003: not enough actual
parameters for macro...So could anybody explain how something like this
is done?


How about

#define DECLARE_NAMED(name) DECLARE_SOMEWNDSTRUCTURE(1,2,3,4,5,name,7)
#define DECLARE_DEFAULT DECLARE_NAMED( 6 )

But I guess this macro evilness is just a symptom of something more
sinister.

Technically you're trying to invent default macro arguments in order to
solve some problem. It's difficult to see what that problem is. But
let's say (correct me if I'm wrong) that the problem is

* How to provide default values for most values in a collection.

And one way to do that is to copy a default collection and simply change
the value or values that should not default, e.g.

ValueCollection defaultValues() { ... }

ValueCollection valuesWithName( std::string const& aName )
{
ValueCollection result = defaultValues();
result.name = aName;
return result;
}

Or it could be an override of a virtual function, like

ValueCollection Base::values() const { ... }

std::string Derived::name() const { return "abra kadabra"; }

ValueCollection Derived::values() const
{
ValueCollection result = Base::values();
result.name = name();
return result;
}

You could even go so far as to use one virtual function per value.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 23 '06 #3
Your code generates a error C4003: not enough actual parameters for
macro 'PRINT3D'

Mar 23 '06 #4
"John Vielerki" <me*********@yahoo.com> writes:
Your code generates a error C4003: not enough actual parameters for
macro 'PRINT3D'


What code?

Read <http://cfaj.freeshell.org/google/> to understand why your post
made no sense, and how to fix it next time.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 23 '06 #5
Sry, I sometimes forget that not everyone uses Google :( Here you go.:
I got a macro like this in my code.

#define DECLARE_SOMEWNDSTRUCTURE(style, nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStruct()\
{\
static SOMEWNDSTRUCT somestruct = {\
style, bits, clrref, icon, tablenum, name, menuname};\
return somestruct ;\
}

And I want to be able to do something like this
Have a generic paremeter list...
GENERIC 1,2,3,4,5,6,7
GENERICNAME(name) 1,2,3,4,5,name,7

Which then could be used like this.
DECLARE_SOMEWNDSTRUCTURE(GENERIC)
DECLARE_SOMEWNDSTRUCTURE(GENERICNAME("Jimbo"))

Obviously this doesn't work - warning C4003: not enough actual
parameters for macro...So could anybody explain how something like this
is done?


Here's an example of how to do it (with some trivial test code; this
has been tested):

#define PRINT3D(a,b,c) do {printf("%d%d%d\n",a,b,c);} while(0)
#define MACROCALL(x,y) x(y)
#define P3DARGS 1,2,3

#include <stdio.h>

int main(void)
{
MACROCALL(PRINT3D,P3DARGS);
return 0;
}

In many preprocessor problems, an extra level of macro expansion is all
that is needed. This shouldn't be too hard to adapt to your code.

Your code generates a error C4003: not enough actual parameters for
macro 'PRINT3D'


Mar 23 '06 #6
On 23 Mar 2006 15:09:03 -0800, in comp.lang.c , "John Vielerki"
<me*********@yahoo.com> wrote:
Sry, I sometimes forget that not everyone uses Google :(


Scary, given that in fact its more to the point that hardly anyone
uses google...

please also see:

<http://cfaj.freeshell.org/google/>
Mar 24 '06 #7
"John Vielerki" <me*********@yahoo.com> writes:
Sry, I sometimes forget that not everyone uses Google :( Here you go.:


[ followup with context snipped ]

Thanks! But pleae don't snip the attribution lines; it can be helpful
to know who wrote what.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 24 '06 #8
Mark McIntyre <ma**********@spamcop.net> writes:
On 23 Mar 2006 15:09:03 -0800, in comp.lang.c , "John Vielerki"
<me*********@yahoo.com> wrote:
Sry, I sometimes forget that not everyone uses Google :(
Scary, given that in fact its more to the point that hardly anyone
uses google...


Alas, that's not the case.
please also see:

<http://cfaj.freeshell.org/google/>


He already did.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 24 '06 #9
On Fri, 24 Mar 2006 00:24:11 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:
On 23 Mar 2006 15:09:03 -0800, in comp.lang.c , "John Vielerki"
<me*********@yahoo.com> wrote:
Sry, I sometimes forget that not everyone uses Google :(


Scary, given that in fact its more to the point that hardly anyone
uses google...


Alas, that's not the case.


There's around eight billion people in the world., I sincerely doubt
that most of them use google.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 24 '06 #10
Mark McIntyre <ma**********@spamcop.net> writes:
On Fri, 24 Mar 2006 00:24:11 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:
On 23 Mar 2006 15:09:03 -0800, in comp.lang.c , "John Vielerki"
<me*********@yahoo.com> wrote:

Sry, I sometimes forget that not everyone uses Google :(

Scary, given that in fact its more to the point that hardly anyone
uses google...


Alas, that's not the case.


There's around eight billion people in the world., I sincerely doubt
that most of them use google.


More like 6.5 billion, and that's not relevant to the claim that
"hardly anyone" uses Google, and who cares anyway?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 24 '06 #11
My remarks were not to convey that I believe everyone uses
Google.....It was to convey that I am self absorbed and could give a
shit what they use. ;)

Mar 24 '06 #12
On Fri, 24 Mar 2006 01:38:30 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:

There's around eight billion people in the world., I sincerely doubt
that most of them use google.
More like 6.5 billion, and that's not relevant to the claim that
"hardly anyone" uses Google,


Its highly relevant. No matter how you work it, the percentage of the
worlds population that uses google isn't appreciable.

Or were you thinking of including only people who use usenet? Why?
and who cares anyway?


Quite :-)
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 24 '06 #13
Jack Morgan wrote:
My remarks were not to convey that I believe everyone uses
Google.....It was to convey that I am self absorbed and could give a
shit what they use. ;)


And we're supposed to care what you say?

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Mar 24 '06 #14
> And we're supposed to care what you say?
We? Are you a member of collective? ...I swear I hate people that feel
the need to pretend they are a group, like somehow their bs becomes
more meaningful.

And we're supposed to care what you say?

Could care less.

Mar 25 '06 #15
On 24 Mar 2006 17:25:44 -0800, in comp.lang.c , "Jack Morgan"
<me*********@yahoo.com> wrote:
And we're supposed to care what you say?

We? Are you a member of collective?


We, thats as in the people that read this group.
And we're supposed to care what you say?


Could care less.


Its worth considering thats its YOU that asked for help, and being
abusive to the people you asked is generalyl considered stupid.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 25 '06 #16

"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:c7********************************@4ax.com...
On Fri, 24 Mar 2006 01:38:30 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:

There's around eight billion people in the world., I sincerely doubt
that most of them use google.


More like 6.5 billion, and that's not relevant to the claim that
"hardly anyone" uses Google,


Its highly relevant. No matter how you work it, the percentage of the
worlds population that uses google isn't appreciable.

Or were you thinking of including only people who use usenet? Why?
and who cares anyway?


Quite :-)


Please, don't feed the troll.
Mar 25 '06 #17

"Mark McIntyre" <ma**********@spamcop.net> wrote in message
news:do********************************@4ax.com...
On 24 Mar 2006 17:25:44 -0800, in comp.lang.c , "Jack Morgan"
<me*********@yahoo.com> wrote:
And we're supposed to care what you say?

We? Are you a member of collective?


We, thats as in the people that read this group.
And we're supposed to care what you say?


Could care less.


Its worth considering thats its YOU that asked for help, and being
abusive to the people you asked is generalyl[sic] considered stupid.


Please, don't feed the troll.
Mar 25 '06 #18

"Default User" <de***********@yahoo.com> wrote in message
news:48************@individual.net...
Jack Morgan wrote:
My remarks were not to convey that I believe everyone uses
Google.....It was to convey that I am self absorbed and could give a
shit what they use. ;)


And we're supposed to care what you say?


Please, don't feed the troll.
Mar 25 '06 #19
On 2006-03-24, Mark McIntyre <ma**********@spamcop.net> wrote:
On Fri, 24 Mar 2006 01:38:30 GMT, in comp.lang.c , Keith Thompson
<ks***@mib.org> wrote:
Mark McIntyre <ma**********@spamcop.net> writes:

There's around eight billion people in the world., I sincerely doubt
that most of them use google.


More like 6.5 billion, and that's not relevant to the claim that
"hardly anyone" uses Google,


Its highly relevant. No matter how you work it, the percentage of the
worlds population that uses google isn't appreciable.


The % of PC/Web users that use google is very appreciable. And that is
why it is important that they get their google groups interface sorted
out - google is rapidly becoming a central "hub" for people to search
for info, pictures, music, usenet posts etc. gmail is taking off at a
tremendous rate : free, big storage, great interface compareed to the
other freebies. "google" is now a verb/noun in the english
language.

Mar 25 '06 #20
> >> And we're supposed to care what you say?
We? Are you a member of collective?
We, thats as in the people that read this group.

So they elected you to speak for them?
And we're supposed to care what you say?
Could care less.


Its worth considering thats its YOU that asked for help,

Yea, keyword help...Not some asshole whining because his newsreader
sucks.
and being
abusive to the people you asked is generalyl considered stupid.
Mark McIntyre

Good thing I wasn't abusive to the people that helped me. :D

Mar 26 '06 #21
A troll saying don't feed the trolls, laughable.

Mar 26 '06 #22
A troll saying don't feed the trolls, laughable.

Mar 26 '06 #23
A troll saying don't feed the trolls, laughable.

Mar 26 '06 #24
On 2006-03-25, John Vielerki <me*********@yahoo.com> wrote:
>> And we're supposed to care what you say?
>We? Are you a member of collective?


We, thats as in the people that read this group.

So they elected you to speak for them?
>> And we're supposed to care what you say?
>
>Could care less.


Its worth considering thats its YOU that asked for help,

Yea, keyword help...Not some asshole whining because his newsreader
sucks.

and being
abusive to the people you asked is generalyl considered stupid.
Mark McIntyre

Good thing I wasn't abusive to the people that helped me. :D


Its kind of scary how many self appointed group police are here in
..c. Far more than in .c++ funnily enough.

The amount of threads littered with "read this on google" and "what code"
and "off topic" is truly scary : especially when there are many others
willing to help in the same thread. The "usual suspects" are a small
but very tight knit group : some of them even quote the others in
their .signatures. To this date one of my favorites is one of the C
gods telling some poor confused C newbie that "and etc." was a syntax
error in C. Invariably they make the mistake that because someone is
asking a C question then they are new to systems and systems
programming and C : and then they pounce. I think they have a league
for who can say "that produces undefined behaviour" first and the most
frequently in any given day at the office.

Some only post warnings about posting style and never actually
contribute any help in the C programming environment itself.

Some fellow also told some to "fuck off" the other day because they didnt
understand his help. Maybe the term "abusive" means something
different in this ng? :-;

ps guys, A threaded newsreader would help a lot of you keep "context"
.... The rest of use really dont need to filter 200 of your warnings
about using google reply every session. Mention it if, and only if, you
are replying to help the OP. The highest form of flattery is
imitation. If you help people they will pick up on your advice/style too.

Sorry if some of the above was "off topic" .... :-;
Mar 26 '06 #25
On Sat, 25 Mar 2006 23:44:07 +0100, in comp.lang.c , "Richard G.
Riley" <rg****@gmail.com> wrote:
Mark said
There's around eight billion people in the world., I sincerely doubt
that most of them use google.
The % of PC/Web users that use google is very appreciable.
The original remark I made was "hardly anyone uses google". This is
true, in the context I was discussing.
And that is
why it is important that they get their google groups interface sorted
out
Its important in an absolute sense too - broken software is bad.
- google is rapidly becoming a central "hub" for people to search
for info, pictures, music, usenet posts etc. gmail is taking off at a
tremendous rate


Or so, at least, Google's marketing team would have you believe.

: free,

Someone is paying for it, wait, who could it be, its you and me, via
forcibly inserted advertising. Sure, use gmail, but don't forget
they're harvesting your _private_ email for marketing info, just as
they previously tried harvesting your public web browsing habits.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 26 '06 #26
On 25 Mar 2006 15:58:33 -0800, in comp.lang.c , "John Vielerki"
<me*********@yahoo.com> wrote:
Its worth considering thats its YOU that asked for help,
Yea, keyword help...Not some asshole whining because his newsreader
sucks.
Well, thats smart of you, I should imagine you're straight into the
killfiles of most of the regulars.
and being
abusive to the people you asked is generalyl considered stupid.
Mark McIntyre

Good thing I wasn't abusive to the people that helped me. :D


Its unlikely to matter - everyone can read your posts, addressed to
them or not, and can see what sort of poster you are.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 26 '06 #27
Don't you have other people to be harassing/whining to?

Mar 28 '06 #28
John Vielerki wrote:

Don't you have other people to be harassing/whining to?


Oh, Mark will take care of them also. Don't worry about it.

F'ups set.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
Mar 28 '06 #29

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Andrew Dalke | last post: by
699 posts views Thread by mike420 | last post: by
50 posts views Thread by Jack Morgan | last post: by
10 posts views Thread by Praveen.Kumar.SP | last post: by
5 posts views Thread by Francois Grieu | last post: by
2 posts views Thread by Christof Warlich | last post: by
7 posts views Thread by Paul | last post: by
36 posts views Thread by sh.vipin | last post: by
12 posts views Thread by webinfinite | last post: by

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.