|
 |
Phil Clute <pcl### [at] tiac net> wrote:
: I have to admit my experience with C programming is extremely
: limited. I guess I am confused as to what a "macro" is then.
: I assumed that constants were macros. What makes #define a
: macro and #declare not a macro? They seem to serve the same
: purpose.
A macro identifier is completely replaced by its value. For example:
#define PrintStatus printf("This is the status\n")
Now you can type something like:
void Function(void)
{ PrintStatus;
}
When parsing, the compiler substitutes the macro, so it converts it to:
void Function(void)
{ printf("This is the status\n");
}
Povray #declared identifiers do _not_ work this way. For example, you can't
make this:
#declare MyTexture=texture { pigment { rgb 1 } }
sphere { 0,1 MyTexture }
Povray does _not_ substitute the identifier "MyTexture" with its value, ie.
the result is _not_ this:
sphere { 0,1 texture { pigment { rgb 1 } } }
Instead, povray will issue an error:
error: No matching } in sphere, texture identifier found instead.
However, #macros work in povray exactly like #defines in C. You can make
this:
#macro MyTexture() texture { pigment { rgb 1 } } #end
sphere { 0,1 MyTexture() }
and it will work.
You can make this same thing in C:
#define MyTexture() texture(whatever)
and when you type "MyTexture()" it will be substituted with
"texture(whatever)" (of course the parenthesis are obsolete here). You can
also give arguments the the #defined macro, just like to the povray
#macro.
A better naming for the commands would be, for example, #let instead
of #declare and #define instead of #macro (although #macro is ok). Of
course it's too late now.
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |