Groovy hepcat (e-mail address removed) was jivin' on 29 Apr 2005 21:23:41
-0700 in comp.lang.c.
Using define with variable values's a cool scene! Dig it!
The following line of code works, however, since my professor is a real
purist of c, I would like to know if this code is valid (is it good
code or a piece of crap?):
Piece of crap. (Well, you did ask.)
#define DMP_FILE argv[argc-1]
This would be use to do something like this:
void main(int argc,char *argv[])
It has been stated time and time again in this newsgroup that main()
must return an int, not void. Inspite of us saying this until we're
blue in the face, you still define main() with a return type of void.
Not a good start!
Of course, as well as making main() return an int, you should
actually have it return something. Portable return value for main()
are 0, EXIT_SUCCESS and EXIT_FAILURE (the latter two being macros
defined in stdlib.h).
int main(int argc, char **argv)
{
FILE *p2file=fopen(DMP_FILE,"w");
There are a couple of problems here. Firstly, your macro DMP_FILE
assumes that argc > 0. This may not be always be the case. You
shouldn't take it for granted.
Secondly, you have not included stio.h, and so you don't have a
valid declaration of fopen() in scope.
return 0;
No. This (the thing in the code directly above) is a function. Its
name is main(). It uses a macro, whose name is DMP_FILE, which is
defined above it.
Cause in the examples of macro I've studied, variables
were involved in the macro itself. This would be like a regular define,
but with variable values.
Macros do not contain variables. However, function-like macros may
have parameters. This allows the user to pass values (from variables
or otherwise) to macros.
--
Dig the even newer still, yet more improved, sig!
http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?