Re: alternate function names
From: Derk Gwen (derkgwen_at_HotPOP.com)
Date: 12/10/03
- Next message: Andy: "Re: 32-bit IEEE float multiplication"
- Previous message: nrk: "Re: Reading a line from a file"
- In reply to: phil-news-nospam_at_ipal.net: "alternate function names"
- Next in thread: phil-news-nospam_at_ipal.net: "Re: alternate function names"
- Reply: phil-news-nospam_at_ipal.net: "Re: alternate function names"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 10 Dec 2003 01:44:15 -0000
# What I have been doing with this is giving the macro the interface name and
# naming the function slightly different. I have been putting a "_" in front
# of the function name, which I want to get away from doing. So I have a macro
# like:
You can have a function name the same as a #define with arguments. Parenthesise
the function name but not the #define:
#define xyzzy(parrot) (xyzzy)(parrot-2,parrot+2)
int (xyzzy)(int plugh,int plover);
int (xyzzy)(int plugh,int plover) {
return plugh*plover;
}
int main(int argc,char **argv) {
printf("%d\n",(xyzzy)(4,8));
printf("%d\n",xyzzy(6));
return 0;
}
# #define strjoin(a...) (_strjoin(a,((const char*)(NULL))))
# and a function definition like:
# char *_strjoin(const char *s,...)
#
# The alternative I'm looking at is to just use the same name for both macro
# and function, like:
# #define strjoin(a...) ((strjoin)(a,((const char*)(NULL))))
# and:
# char *(strjoin)(const char *s,...)
#
# This approach works, but I'm worried about confusion it may cause. So what I
# want to do here is see if there is a better alternative to using a different
As long as you use #defines with arguments and parenthesise the function name,
there will be no confusion in the compiler. (If you look at some of your
implementation standard headers, you'll see them doing this trick.) Whether
it confuses other programmers is a different issue.
-- Derk Gwen http://derkgwen.250free.com/html/index.html This is one wacky game show.
- Next message: Andy: "Re: 32-bit IEEE float multiplication"
- Previous message: nrk: "Re: Reading a line from a file"
- In reply to: phil-news-nospam_at_ipal.net: "alternate function names"
- Next in thread: phil-news-nospam_at_ipal.net: "Re: alternate function names"
- Reply: phil-news-nospam_at_ipal.net: "Re: alternate function names"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|