Re: C is too old? opinions?



jacob navia <jacob@xxxxxxxxxxxxxxxx> writes:
[...]
Tor Rustad <tor_rustad@xxxxxxxxxxx> writes:
jacob navia wrote:
[...]
Why not

#pragma once
Chapter and verse please.
[...]

It is supported by
1) MSVC (windows)
2) Intel compiler
2) Comeau C/C++ (Unix and windows)
3) Digital Mars C/C++ (Unix+Windows I think)
4) gcc (versions later than 3.4) (Unix)
5) lcc-win32 (Windows)
6) Delorie C/C++ (MSDOS)
7) MIPS PRO C/C++ (SGI)
8) Code Warrior (MacIntosh version)
9) Digital C++ (Unix)
10) MPW C compiler (Macintosh)
11) The Watcom compiler

The very fact that you need to list the implementations that support
it emphasizes the fact that it's non-standard.

If you happen to have the luxury of assuming that your code will be
compiled only by compilers that support '#pragma once', then it might
make sense to use it. If you intend your code to be as portable as
possible, if you don't *know* what compilers may be used to compile
your code, you need to use the old '#ifndef' trick.

For that matter, how sure can you be that all 11 of those compilers,
and all other compilers that happen to implement '#pragma once', do so
with exactly the same syntax and semantics? And do all of those
compilers accept '#pragma once' when invoked in either C90 or C99
conforming mode? If not, it could be used only at the cost of losing
checks for other non-standard constructs, even on compilers that
support it.

On some systems, there are corner cases that could cause problems.
Presumably when '#pragma once' is encountered, it causes the compiler
to remember the name of the current file and to ignore any future
#include directives for that file. But what happens if the same file
is referred to by two different names? There are a number of ways
this could happen on Unix-like systems, for example. Such problems
probably aren't too difficult to avoid, but I'd want to have a precise
definition of the feature before I'd feel comfortable using it.

(Incidentally, I just checked the gcc documentation, to see if I could
find *some* specification for '#pragma once'. It doesn't mention it
at all.)

If you want to suggest '#pragma once', that's ok with me, but *please*
don't do so without mentioning that it's non-standard. It's a nice
feature, and I wouldn't mind having it in the standard (though
defining it precisely might be difficult), but there is a cost to
using it.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • ANN: kbmMemTable v. 4.05 released
    ... - Added support for sfLoadIndexDef in sfIndexDef in binary and csv streamformats. ... (LEVEL6+ compilers only). ... This allows for the index to show or filter specific updatestatus settings incl. ... Reported by Rado Antloga. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Any plans to remove obsolescent features?
    ... bother to support it. ... It's either deprecated or a syntax error (i.e. not ... compilers to still support it as an extension-- as long as a diagnostic is ... first -- it was those other languages that decided to become inconsistent ...
    (comp.std.c)
  • Re: Very basic Fortran compiler question
    ... For whatever reasons, ... > Fortran compilers, I've turned in problem reports and gotten ... > have not had such good support experiences with are no longer ... I would say that the primary criteria for determining what software to ...
    (comp.lang.fortran)
  • Re: reading a text file into a string
    ... it should be supported by all compilers. ... compilers that do support such alignments, ... case of a String buffer when reading files is a perfect case in point. ... cache line, then that line will stay resident in L1 cache. ...
    (comp.lang.ada)
  • the 5 questions...with my comments/answers
    ... > only compiler left: Delphi. ... We are still building compilers. ... > Borland itself shows that is very dangerous thing. ... We are supporting .NET just as we support MS ...
    (borland.public.delphi.non-technical)