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? 28 6190
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.
* 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?
Your code generates a error C4003: not enough actual parameters for
macro 'PRINT3D'
"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.
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'
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/>
"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.
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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 ;\
|
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,...)
|
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
| |
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, ..};
|
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);
|
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;\
|
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.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |