Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Using the pre-processor

carlls
Beginner
720 Views
I have the following constructs in place for language inter-operability

void CALLMETH hello_world()
{
}

So that on the command line I can say

-DCALLMETH=stdcall

And this works fine but how do I null out CALLMETH?

I have tried

-DCALLMETH=" "

and while this seems to work on a typed in command, tossing it into a Cygwin shell script it gets really messy.

Can I use some incantation using # or ## here ? All I really want to do is turn CALLMETH in whitespace.

By the way just using -DCALLMETH replaces CALLMETH with the number 1 ( as it should ).

Regards
Carl
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
720 Views
I don't quite follow the context, i.e. when you want to undefine the symbol?

There's /undefine (/U) compiler switch which does the undefinition, but it's not clear to me what's its scope.
0 Kudos
jimdempseyatthecove
Honored Contributor III
720 Views

Carl,

This is a C problem question on a Fortran forum. That said consider inserting into a common header

#ifndef CALLMETH
#define CALLMETH
#endif

Then in your IDE settings (or command line) either a) define CALLMETH (as stdcall etc...) or b) not define CALLMETH.
When not defined, the above sets CALLMETH to empty space.

Jim Dempsey
0 Kudos
carlls
Beginner
720 Views
Actually it is posted here because Intel FORTRAN now supports FPP (a cpp clone) so pre -processor usage is applicable to both FORTRAN and C,and this revolves around c and fortran interoperability. (sorry if I sound testy ... had my head inside compilers for to long)

Coming out of the CVF world we used the paradigm for C functions as

int CALLMETH c_to_be_called_by_f()
{
}

and we would do a -DCALLMETH=STDCALL

and after running the preprocessor the line would become:

int STDCALL c_to_be_called_by_f()

which was fine for CVF, but now under IF9.1 (since Intel is adopting the MS calling conventions by default)

the line needs to become

int c_to_be_called_by_f()

effectively nulling out the preprocessor macro.

Now the previous suggestion of -U (undefine the fpp macro) doesn't work because the code the compiler sees is really .....

int CALLMETHc_to_be_called_by_f()

and this makes no sense at all to a compiler.

I have tried a "hack" of

-DCALLMET=/**/

which results in a line that should look like ...

int /**/ c_to_be_called_by_f()

which most C compilers should take, but kinda looks ugly, and what is the equivalent in FORTRAN?







0 Kudos
IanH
Honored Contributor III
720 Views
Keep the =, but don't put anything after it other than one or more spaces (or have it at the very end of the command line).

If you were applying this to a fortran program:

ifort /fpp /DCALLMETH= ...rest of the command line...

Are you aware of the C interoperability feature introduced with the Fortran 2003 standard? Life in between the C and Fortran worlds is much simpler if you take advantage of this.

IanH
0 Kudos
Jugoslav_Dujic
Valued Contributor II
720 Views
Quoting - carlls
and after running the preprocessor the line would become:

int STDCALL c_to_be_called_by_f()

which was fine for CVF, but now under IF9.1 (since Intel is adopting the MS calling conventions by default)

the line needs to become

int c_to_be_called_by_f()


For that particular case, you can define it to be "_cdecl" for IVF (and for CVF, better use "_stdcall" than "STDCALL" -- the first one is built-in in the MSVC compiler and the other comes from windows.h).

For a general case, I don't know. Maybe -DCALLMET="�" will work, but it's a wild guess.


0 Kudos
Reply