Box 24

 Home   Infos   Tipps   Webmail   Humor   Polizei   Gästebuch   Downloads   Chat   Suchen   Feedback   Links 

 

 Anmelden/Login   Neuanmeldung/New User   Java Telnet Applet   Telnet   
 

Compiler pragma directives

(since 5.4.449.5)

Compiler pragma directives

#pragma once

compiles header file only once

#pragma exclude

exclude module (non-library) from menus

Conditional compilation directives:

#define tag

#undef tag

#ifdef tag or #ifndef tag

#else  or #elseif tag

#endif

Compiler pragmas are special commands normally found in native languages like c/c++. They are used to set special compiler instructions.

A small set of pragmas are defined for Wildcat:

#pragma once

This pragma is typically added to the top of header files to inform the compiler not to include it again. There are times where you might have included a header file more than once indirectly thru another header file. This is not incorrect and is normally good practice to have a well modulized set of header files which automatically include what they required.

However, without this pragma, you would get a compiler error saying "something was already defined". For example, see wsockhlp.wch and winsock.wch header files. wsockhlp.wch includes winsock.wch. If you included winsock.wch again in the main module, you would get a compiler error. With the #pragma once line added to winsock.wch, the compiler will not include it again.

#pragma exclude

Non-library modules are listed in the menu access list box allowing you to select the access for each module. However some modules are designed to be run from the WCC command line and there is no need to list them. It doesn't hurt to have them there but it would be cleaner to "exclude" from the list. This pragma will achieve this purpose. Use it for "stand-alone" modules.

Conditional Directives:

Now it is possible to create #define tags to perform conditional compilation. To best understand the need for this, consider how you would attempt to do this now without conditional directives:

const debugEnabled = FALSE
if DebugEnabled then
  print "Debug version"
else
  print "Non-Debug version"
end if

with conditional directives, you would do:

#define DebugEnabled
#ifdef DebugEnabled
  print "Debug version"
#else
  print "Non-Debug version"
#endif

The difference? In the first case, the entire program is compiled and in the second case, only the lines which satisfy the condition are compiled. In other words, you will have a smaller program. This is a simple situation. But you can also use compiler directives to support multiple different versions of your applications. For example:

#define VERSION1
//#define VERSION2
//#define VERSION3

#ifdef version1
  print "compiling for version1"
#elseif version2
  print "compiling for version2"
#elseif version3
  print "compiling for version3"
#else
  // Force compiler error using syntax error Version not defined!
#endif

With the above example, you can simple change the define statement to compile the parts of the code you want.

Special Note:

In c/c++ a #define tag could be used for substitution in the code, for example:

#define tag value
printf("tag=%s",tag);

Then whereever in the program the tag appears, it would be replaced with value.

This is not the case in wcBASIC. You can not use #define to place values in the source code.

However, you can accompish the same task by using the CONST keyword instead like so:

const tag=value;
print "tag=";tag

The #define tag statement in wcBASIC is simply for usage with conditional directives (#ifdef, etc).

 

© 2001 Hector Santos, http://www.santronics.com