473,654 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro parameter list

I got a macro like this in my code.
#define DECLARE_SOMEWND STRUCTURE(style , nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStru ct()\
{\
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(nam e) 1,2,3,4,5,name, 7 Which then could be used like this.
DECLARE_SOMEWND STRUCTURE(GENER IC)
DECLARE_SOMEWND STRUCTURE(GENER ICNAME("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 6189

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

#define DECLARE_SOMEWND STRUCTURE(style , nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStru ct()\
{\
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(nam e) 1,2,3,4,5,name, 7

Which then could be used like this.
DECLARE_SOMEWND STRUCTURE(GENER IC)
DECLARE_SOMEWND STRUCTURE(GENER ICNAME("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(PRINT 3D,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_SOMEWND STRUCTURE(style , nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStru ct()\
{\
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(nam e) 1,2,3,4,5,name, 7
Which then could be used like this.
DECLARE_SOMEWND STRUCTURE(GENER IC)
DECLARE_SOMEWND STRUCTURE(GENER ICNAME("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(n ame) DECLARE_SOMEWND STRUCTURE(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*********@ya hoo.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_Keit h) 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_SOMEWND STRUCTURE(style , nums, clrref, icon, tablenum,
name,
menuname)\
static SOMEWNDSTRUCT &GetSomeWndStru ct()\
{\
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(nam e) 1,2,3,4,5,name, 7

Which then could be used like this.
DECLARE_SOMEWND STRUCTURE(GENER IC)
DECLARE_SOMEWND STRUCTURE(GENER ICNAME("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(PRINT 3D,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*********@ya hoo.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*********@ya hoo.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_Keit h) 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**********@s pamcop.net> writes:
On 23 Mar 2006 15:09:03 -0800, in comp.lang.c , "John Vielerki"
<me*********@ya hoo.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_Keit h) 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.or g> wrote:
Mark McIntyre <ma**********@s pamcop.net> writes:
On 23 Mar 2006 15:09:03 -0800, in comp.lang.c , "John Vielerki"
<me*********@ya hoo.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
3234
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 clarification on what 'macro' means. A Lisp macro is a way of modifying code when that code is first defined. It can rearrange the structure of the code, and add and remove parts of it. Unlike C's #define macro language, Lisp macros understand the...
699
33862
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
50
1059
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 somestruct = {\ style, bits, clrref, icon, tablenum, name, menuname};\ return somestruct ;\
10
9836
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
6289
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 directive in the middle of macro arguments, which comes handy e.g. to
2
2319
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. The reason why I need this: I want a fixed Index->Value mapping that should be part of a compile time API. The straight forward way to do this would be an array, e.g.: const int Mapper = {27, 225, 815, 4711, ..};
7
1743
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 making this work (using the preprocessor)? #define MyList 1,2,3,4 #define Sum(a,b,c,d) a+b+c+d x = Sum(MyList);
36
2535
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;\ unsigned int a2;\
12
1834
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
8294
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8709
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7309
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.