473,394 Members | 1,828 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,394 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 6147

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
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...
699
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...
50
by: Jack Morgan | last post by:
I got a macro like this in my code. > #define DECLARE_SOMEWNDSTRUCTURE(style, nums, clrref, icon, tablenum, name, menuname)\ static SOMEWNDSTRUCT &GetSomeWndStruct()\ {\ static SOMEWNDSTRUCT...
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
5
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing...
2
by: Christof Warlich | last post by:
Hi macro experts, in a variadic macro, i.e. in a macro with a variable parameter list, is there any way to access single parameters of the list? __VA_ARGS__ only expands to the whole list. ...
7
by: Paul | last post by:
I would like to define a list of parameters, and then pass them to a macro. However, the compiler (gcc) only sees one parameter, rather than expanding the definition. Could anyone suggest a way of...
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
12
by: webinfinite | last post by:
#define D(y...) (const int ) {y} My understand is that D is taking in a various length parameter y which is an array of const int. Am I right? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
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
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...
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
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...
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...

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.