Re: Using define with variable values



In article <1114835021.236146.283510@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
<msigwald@xxxxxxxxx> wrote:
>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?):
>#define DMP_FILE argv[argc-1]

It is completely legitimate C. There are two kinds of #define,
one "object like" and the other "function like". Either one is
permitted to include a wide range of syntax, not limited to
constants or variables or simple expressions. It is valid C to
use something like #define BEGIN {
or to otherwise appear to distort the syntax of C.

Whether it is good -style- is a different question.


>This would be use to do something like this:
>void main(int argc,char *argv[])
>{
> FILE *p2file=fopen(DMP_FILE,"w");
>}
>

What happens if no arguments were passed? Are you going to
overwrite the binary executable itself?
--
Warning: potentially contains traces of nuts.
.



Relevant Pages

  • Re: Pseudo variables or substring operators?
    ... it would be worth a special syntax (I agree it would be nice, ... can't do functions, expressions, or other substrings. ... array indices and slices have the same issue as substrings. ... simpler for compilers, but that compiler technology advanced enough ...
    (comp.lang.fortran)
  • Re: Maybe something to vote for...
    ... IMO, if the syntax can't handle everything in a coherent fashion, then ... You dont have to ... overwrite a variable. ... the pointer also. ...
    (borland.public.delphi.non-technical)
  • Re: lambn
    ... rather than Lambda Expressions. ... need XPath syntax for, for example, XSLT. ... LINQ is a language that attempts ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regular expression
    ... is do different applications have different dialects for regular ... variations of regular expression syntax. ... Expressions). ...
    (comp.sys.mac.system)
  • Re: subroutine stack and C machine model
    ... Okay, given that, it seems to me that the only expressions which can ... you can't tell by looking at syntax whether a variable is volatile-qualified, ... volatile int i = 3; ... at the syntax level, and the latter looks to me to contain a side effect. ...
    (comp.lang.c)