How to write C-like macros?

How do I write C-like macros in Pascal?

Simply put, how do I translate the following C statements into Pascal?

#define sqr(x) (x * x)
#define X Y
venkat_rsAsked:
Who is Participating?
 
sumant032199Connect With a Mentor Commented:
I think that can not be done and better if we don't do it. What I mean is macros are really special things in C and C++. They are used as compiler diretive. Let this feature of C and C++ be with them alone, afterall these things are identities of C and C++ language compilers.As you may be knowing many good pascal identities are not included in latest C, C++ compilers,
why? No. Just to maintain its identity.
I think. And hence you won't find any Pascal compiler supporting C like macros.
0
 
ozoCommented:
You could process your Pascal program through the C pre-processor.
0
 
venkat_rsAuthor Commented:
No, I don't want to do that! I'd like to have an equivalent of #define in my .INC file.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nricoCommented:
Immmmmmpossible!
0
 
nricoCommented:
Okay, one should never say that, especially in computer business... :-)
0
 
vikiingCommented:
C compiler makes "precompiling" (it's often a separated executable program), whose one of its missions is to make macro conversions.

On the other hand, Pascal nas nothing like that. You're dead.
0
 
scrapdogCommented:
You're totally out of luck.  Even Super-Duper-Pascal (Delphi) doesn't have this ability, though I would love to have it.

If you could do like ozo says and pipe the program from a C pre-processor to a Pascal compiler, it is possible, but may be more trouble than it is worth.

One of the characteristics of Pascal (at least Turbo and Delphi) is that it is compiled in one pass.
0
 
joe_hCommented:
If you are using BP, it should be possible to add something like "Preprocess & compile" to the Tools menu. You'd run cpp and then send its output to bpc (command-line BP compiler).
0
 
nils pipenbrinckCommented:
jep.. I agree..

there are a lot of free preprocessor tools out there.. alsmost any of them would do the job (or be cool and write one yourself).

it's not that difficult, however, I don't know how to integrate that into the bp ide.. (I guess that will be more trouble than writing the preprocessor itself).

0
 
venkat_rsAuthor Commented:
Thanx for the elaborate answer, sumant. But, my idea is not to ask for introducing #define into Pascal, but to know how I can achieve such a usage in Pascal.

Maybe, it's time I closed this question thread.
0
All Courses

From novice to tech pro — start learning today.