Function Allocation Using __based

Due to bug fixes since version 6.0 of the compiler, programs that use __based incorrectly may not compile with Microsoft C, version 7.0.

Only lvalues may be converted to __based((__segment)__self) pointers. Since the right side of an assignment gets converted to the type of the left hand side, this means you must now use an explicit cast when assigning to a __based((__segment)__self) pointer. For example,

int __based((__segment)__self) *piself;

piself = 1;

is interpreted as

piself = (int __based((__segment)__self)) 1; /* Illegal! */

but the expression 1 does not have a segment so this is illegal. To put the offset 1 into this based pointer, you must cast it to a __based(void) pointer as shown:

piself = (int --based(void)*) 1;

Similarly,

unsigned short us;

piself = ui;

must be written as

piself = (int __based(void)*) ui;

if you want to move the contents of ui into the __based((__segment)__self) pointer.

Also new to Microsoft C, version 7.0, functions can now be declared as based on a segment constant if a function needs to be allocated in a given segment. This feature replaces the alloc_text pragma.

When a segment name ends with _TEXT, the compiler converts it to a code segment rather than a data segment. For example, for this declaration,

void funct1()

{

static char _based(_segname("MY_TEXT")) arr[] = "A string\n";

}

the C version 6.0 compiler made MY_TEXT a data segment, but the C 7.0 compiler makes MY_TEXT a code segment.

See Chapter 4 of Programming Techniques for more information.