tags:

views:

96

answers:

3

What does "symbol" mean as in "Load Symbol List"? Or as in this example from MSDN:

"#if lets you begin a conditional directive, testing a symbol or symbols to see if they evaluate to true."

Where are these symbols defined and declared?

+5  A: 

"Symbol" is a fairly broad (and overloaded/ambiguous) term in computer science. Wikipedia has an article on them: Identifier/Symbol/Token.

However, in your case, you're looking at preprocessor (precompiler) directives, which affect the results of compiling.

In the case of #if, the "symbol" is just a variable; one such "symbol" is DEBUG which can be used like:

#if DEBUG

The "Debug" symbol will evaluate to true if the code is being compiled under Debug mode--so in those cases the code within the #if block will be sent to the compiler.

You can also use #define which creates a symbol and (more or less) sets its value to true. So, an undefined symbol evaluates as false whereas a defined symbol evaluates to true

STW
I think you mean _DEBUG, if you're using the MSVS defaults.
Hitobat
probably depends on C++ vs C#
STW
At least in C++, `#define X` followed by `#if X` results in a syntax error because the `X` is expanded into no tokens. `#ifdef X` or `#if defined X` is needed to test whether a symbol is defined. To test it using a `#if` directive directly, it must expand to some other tokens, e.g., `1`.
James McNellis
A: 

You can also add your own symbols for use in your code or remove the built in symbols. If you use Visual Studio you do this under Properties for your project and then the build tab. If you don't use Visual Studio I would suspect that this symbols are added to the command line when you compile your program.

/Viktor

Viktor
+1  A: 

For "Load Symbol List", a symbol is a defined element in the syntax of a programming language. A local variable name is a symbol. A class type identifier is a symbol. PDB files contain symbol information so the debugger can know where things reside and what their names were in the original source code.

For #if, "symbol" means a preprocessor (c++) or conditionally defined (C#) symbol. C# doesn't have a preprocessor phase so the terms can be a little confusing.

You define a conditional symbol using #define: #define WIN32 You test for whether a symbol is defined using #if: #if WIN32 <...> #endif

Preprocessor symbols are typeless and generally do not intersect with the types and identifiers that are actually part of your program code. The preprocessor sits "above" your source code. Preprocessor symbols don't exist in the compiled output and don't take up any memory space at runtime. Logically speaking, the compiler never sees the preprocessor syntax - it's removed before the text reaches the compiler proper.

dthorpe
`PDF files contain symbol information...` I guess you meant `PDB files...`
Eugen Constantin Dinca
Doh! Nice catch. Fixed. Thanks.
dthorpe