Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Macro function syntax

Reply
Thread Tools

Macro function syntax

 
 
Ann O'Nymous
Guest
Posts: n/a
 
      07-30-2010
On 7/29/2010 8:34 PM, Shao Miller wrote:
> #define MAXARGS 10
> typedef unsigned int zlink_args[MAXARGS];
>
> int zlink(int(int, ...), int, unsigned int *);
> int zlink(int bar(int, ...), int flags, unsigned int *list) {
> return 12;
> }
>
> unsigned int *buildlist(zlink_args list, ...) {
> /* ... */
> return list;
> }
>
> int foo(int bar, ...) {
> return 5;
> }
>
> #define LINKX(routine,flags,list, ...) \
> (zlink((routine),(flags),buildlist((list), __VA_ARGS__)))
>
> int main(void) {
> zlink_args mylist;
> int w, x, y, z;
>
> w = x = y = z = 10;
> return LINKX(foo, (1<< 3)& (1<< 4), mylist, w, x, y, z);
> }


I'll probably do something like this, although I want to hide the
zlink_args stuff in the macro. Thanks.
 
Reply With Quote
 
 
 
 
Shao Miller
Guest
Posts: n/a
 
      07-30-2010
On Jul 30, 11:39*am, Ann O'Nymous <nob...@nowhere.com> wrote:
> I'll probably do something like this, although I want to hide the
> zlink_args stuff in the macro. *Thanks.

Could you at all be interested in sharing a bit more about your
requirement for building the arguments into an array that's all inside
the macro?

For example, why use a macro at all? You could use a function that
allocates the array, populates it from arguments, then calls 'zlink'
and returns that call's result.

Also, consider a loop where we don't pass 'mylist':

enum { lim = 50 };
int i, rc, w, x, y, z;

w = x = y = z = 0;
for (i = 0; i < lim; i++) {
rc = LINKX(foo, (1 << 3) & (1 << 4), w, x, y, z);
if (rc) {
/* ... */
}
}

If you use Ben's suggestion of C99 compound literals within your
'LINKX' macro, you get nameless objects with automatic storage
duration. When does their lifetime end? If it's the 'for' {} body,
then what's to prevent allocating 50 of them above, as per 'lim'?
That might get expensive.

Are you trying to make minimal changes to someone else's code? Are
you using 'setjmp()' and friends and have concerns about allocating
something like 'mylist' in a function's body? Or maybe you don't wish
to add such an allocation to every function using the 'LINKX' macro?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
object-like macro used like function-like macro Patrick Kowalzick C++ 5 03-14-2006 03:30 PM
Macro lens on a camera with a macro setting??? mitchell.chris@gmail.com Digital Photography 2 09-28-2005 07:55 AM
in S.E. Asia : Canon EOS 300d with 100 macro ED vs. Nikon D70 with Nikon 105 macro ? J. Cod Digital Photography 0 09-29-2004 05:46 AM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
macro name from macro? D Senthil Kumar C Programming 1 09-21-2003 07:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57