Novice MicroSoft C5.1 question

Steve Summit scs at adam.mit.edu
Fri Aug 3 09:26:03 AEST 1990


In article <17179 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:
>
>For portable usage, you should cast the pointer to (void *); it's not always
>true that `int *' and `void *' have the same representation.  Apparently MSC
>requires you to also use the `far' keyword in some memory models, but if they
>claim to be standard conforming, that's a bug%.

In article <440 at demott.COM> kdq at demott.COM (Kevin D. Quitt) writes:
>   MSC's %p prints the pointer in the format SSSS:OOOO (segment/offset), with
>%Np printing only the OOOO portion.  Both forms expect a 32 bit pointer,
>so non-32 bit pointers must be coerced by using the far keyword.

The Standard does not say anything about near and far pointers.
The Standard says that if you pass a void * to %p, the pointer
will be printed in some machine-dependent way.  Karl is correct;
the Microsoft compilers are not ANSI-compliant in this regard.
It's not an academic question, either; the correct and portable
code

	int *ip;
	...
	printf("%p\n", (void *)ip);

will not function as intended under MSC if a small-data memory
model is used, while the "Microsoft compliant" code

	printf("%p\n", (void far *)ip);

is obviously not portable to compilers without a nonstandard far
keyword.  %p can be quite useful, if only when debugging; it's a
miserable pain to have to surround usages of it with #ifdef MSC
or the like when Microsoft compilers are in use.

It has been observed that other segmented architecture/language
combinations than 80*86/C do not make the existence of segments
so manifestly visible at the HLL source level.  Why should a C
programmer be intimately concerned with segments and offsets and
near and far pointers?  (The answer, of course, is obvious:
transparency would most easily be implemented by having "large
model" the default, which would clearly be far "too inefficient.")
Microsoft C v6.0 makes the problem worse, not better: programmers
are encouraged to make use of the new "based pointers" to
"control placement of data in segments and generate better code
for far-pointer manipulation" (this according to the marketing
hype in the compiler documentation).  It looks to me like based
pointers are merely less portable and more confusing.  (I
shouldn't have gone off on this tangent; now the Intel and
Microsoft apologetics will rush to the defense and I'll have
started a flame war...)

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list