From: lupe@ukw.uucp (Lupe Christoph)
Newsgroups: comp.sys.sun.misc
Subject: Re: Sun's ANSI C
Date: 2 Jan 93 19:16:44 GMT
Organization: cic

swofford@uxh.cso.uiuc.edu (David Swofford ) writes:

>alec@stortek.com (Alec Sharp - x2955) writes:

>On page 76-77 of the "Sun ANSI Programmer's Guide" is the following:

>"Some of the functions in SunOS 4.1. libc do not behave as specified by the
>ANSI standard.  These differences are detailed below..." (the ones included
>in your examples plus maybe a few others).

>I was *FURIOUS* when I discovered this.  I bought the compiler because it
>was "Sun ANSI C".  In the preface of the manual it says "Sun ANSI C is Sun's
>ANSI-compliant compiler that runs on SunOS 4.1."  But in the "Read this first"
>section of the manual it says "Sun ANSI C is intended as a transition compiler
>from Sun C to a fully compliant ANSI C".  For most users, the differences
>probably won't matter (e.g., who cares whether malloc returns a char*
>or a void*, since it's almost always cast to something else anyway?).  But
>calling a compiler "ANSI-compliant" when some functions return totally
>different kinds of values is ABSURD.  The one that really got me was sprintf.
>In my application, I need to format a string via sprintf and know how long the
>resulting string is.  ANSI requires sprintf to return an integer representing
>the length of the formatted string, but in Sun's "ANSI" C, sprintf still 
>returns a char*.  So I still have to do strlen calls after sprintf's, when I
>should just be able to look at the sprintf return value, which uglies up the
>code with #if SUN ... #else .... #endif constructs.

Please note that Sun is talking about the *operating system* rather than
the compiler. The SPARCcompiler uses the standard SunOS libraries. And
*I* would be furious if it came with it's own, reducing interoperability.

My 2.0.1 release has an appendix C with a table of differences between
the SunOS 4.1.x, SunOS 5.0, and ANSI C.

>Does anyone know if the unbundled compiler being sold with Solaris 2.x is
>fully ANSI-compliant? 

The same table leave these differences:

---libc---

Sun				ANSI

typedef int size_t		typedef unsigned int size_t
char *memchr(char *,		void *memchr(const void *,
    int, size_t);		    int, size_t);
int memcmp(char *,		int memcmp(const void *,
    char *, int);		    const void *, size_t);
char *memset(char *,		void *memset(void *,
    int, int);			    int, size_t);
char *memcpy(char *,		void *memcpy(void *,
    char *, int);		    const void *, size_t);

There is a library libansi.a that supplies a few missing library functions
for SunOS 4.x. It also redefines some.

---other---

C 2.0.1 does not support "#pragma weak".

"The type qualifier const is not placed in a read-only area of storage."
(Probably means that a "const" can still be changed by casting.)

There is a large number of header files with non-ANSI-isms in 4.x.
-- 
| ...!unido!ukw!lupe  (German EUNet, "bang")     |  Disclaimer:            |
| lupe@ukw.UUCP       (German EUNet, domain)     |  This is an unofficial  |
| suninfo!alanya!lupe (Sun Germany)              |  opinion of Christoph & |
| Res non sunt complicanda praeter necessitatem. |  Imschweiler Consulting |
Newsgroups: comp.sys.sun.misc