Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: C pre-processor in Perl

by adrianh (Chancellor)
on Jul 28, 2003 at 19:46 UTC ( #278589=note: print w/replies, xml ) Need Help??


in reply to C pre-processor in Perl

Could someone tell me why constant is preferable to #define in the following code?
  • constant will work on platforms without cpp (that's the big one for me :-)
  • constant is package scoped. #define is not.
  • With constant you have access to perl at compile time. With #define you do not.
  • Different versions of cpp on different platforms do different things.
  • It's unlikely to be much faster, if at all. The constant's are expanded at compile time so there is no run-time cost using either system. Starting up a cpp process may actually slow down your compile time.
  • require() will include your code only once, compile in a separate lexical file scope, and in package main by default. #include will not.
  • C macros are very much not first class macros IMHO. See Macros, LFSPs and LFMs for more on this.
  • :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://278589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2021-05-15 03:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?