Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Right C version for GCC Date: Sun, 08 Nov 2015 17:00:43 -0800 Organization: None to speak of Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="8175"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vwLHoQhIpRteXBrR5R7LL" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:wIya8wKzCXnlnHnMogHQh1Vi+ik= sha1:XHk2/jBgNBOSNMV+CKultMRWJ80= Xref: csiph.com comp.lang.c:75410 Malcolm McLean writes: [...] > If you want to write portable code, I strongly recommend that you stick > to a conservative subset of C89. No passing or returning of structures > by value, no nested structure definitions, no non-basic types as > members except for structures declared in your own program, > especially wide character types (you can probably get away with > size_t, but I'd also cut it out). C has permitted structure assignment, argument passing, and returning as values from functions since the 1989 ANSI standard, and several years before. K&R1, published in 1978, mentions it as a feature that would be implemented soon. I challenge you to find a C compiler in current use that does not support it. If by "nested structure definitions" you mean using a structure as a member of another structure, I have never heard of a C compiler that did not fully support that. A C reference manual from 1975 includes structs and mentions no such restriction. If not, what exactly do you mean by "nested structure definitions"? C11 supports anonymous structures, but those are easily avoided. If you want maximially portable C code, I suggest using C89 while avoiding any features that are either obsolescent or incompatible with later standards. Using C99 will only slightly reduce your code's portability. Microsoft's c compiler is the one that's the most notorious for its failure to support C99, but it does support *some* C99 features. There are some C (or C-like) compilers, particularly for embedded systems, that don't fully support any C standard. You can't really write portable C code to target such compilers, since the features that are missing are going to vary from one compiler to another. I suggest not worrying about that until and unless you actually need to use such a compiler. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"