Friday, June 15, 2007

The #line Directive

The #line directive tells the preprocessor to change the compiler's internally stored line number and filename to a given line number and filename. The compiler uses the line number and filename to refer to errors that it finds during compilation. The line number usually refers to the current input line, and the filename refers to the current input file. The line number is incremented after each line is processed.

#line digit-sequence "filename"opt

The digit-sequence value can be any integer constant. Macro replacement can be performed on the preprocessing tokens, but the result must evaluate to the correct syntax. The filename can be any combination of characters and must be enclosed in double quotation marks (" "). If filename is omitted, the previous filename remains unchanged.

namaste!

 

The #line Directive - Part2 (Intresting Fact)

The .pdb file generated by the compiler contains line number information to allow the debugger to step through source code. In this for blocks of IL code the corresponding source file and line number information is stored. The #line directive makes the compiler change the line number information it puts into this file. There is an understanding between the debugger and the compiler that if the line number of a block of IL is set as 16707566 ( 0xFeeFee) then the debugger will simply step over this block of code. This is utilized in #line hidden and the compiler translates hidden to 0xFeeFee You can try out the following code to see this in action

using System;
namespace LinePreProcDirective
{
class Program
{
static void foo()
{
Console.WriteLine("foo");
#line 16707566
Console.WriteLine("bar");
#line default
}
static void Main(string[] args)
{
foo();
}
}
}

The code marked in bold will be skipped over if you try to step through this code in the debugger.

namaste!

rename_namespace (#import)

rename_namespace("NewName")

NewName
The new name of the namespace.
The rename_namespace attribute is used to rename the namespace that contains the contents of the type library. It takes a single argument, NewName, which specifies the new name for the namespace.

To remove the namespace, use the no_namespace attribute instead.

namaste!

named_guids (#import)

The named_guids attribute tells the compiler to define and initialize GUID variables in old style, of the form LIBID_MyLib, CLSID_MyCoClass, IID_MyInterface, and DIID_MyDispInterface.

Here is the link to msdn

namaste!