Topic: no bugs, I repeat
Author: allan_w@my-dejanews.com (Allan W)
Date: Tue, 8 Apr 2003 20:32:15 +0000 (UTC) Raw View
jacob@jacob.remcomp.fr (jacob navia) wrote
> > Will lcc-win32 include it twice, thus ignoring the #pragma once?
>
> Yes
>
> > If so, isn't that a bug?
>
> No. It is a network misconfiguration.
It depends on the stated purpose of #once (or #pragma once).
I view it as an optimization. A failed optimization is only a bug if it
causes the wrong results.
#define-style include guards have been around since the earliest days
of C programming. They're easy to write, easy to understand, and they
work very well (given a good naming standard). I teach this to
first-year C++ students.
#define-style include guards do have one shortcoming: in order for the
compiler to skip an already-seen include guard, it has to re-open the
source file, read the appropriate #if statement, scan for the matching
#endif, and finally close the file. While this does not result in any
sort of error, it can slow down the compile process.
#pragma once is an attempt to optimize the performance by skipping the
file read when it is unneccesary. If this optimization fails, the program
is still correct (but it compiles more slowly).
My point, then, is that if you combine #once (or #pragma once) with
traditional include guards, you get the best of all worlds.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: hyrosen@mail.com (Hyman Rosen)
Date: Wed, 9 Apr 2003 02:53:45 +0000 (UTC) Raw View
Allan W wrote:
> #pragma once is an attempt to optimize the performance by skipping the
> file read when it is unneccesary. If this optimization fails, the program
> is still correct (but it compiles more slowly).
>
> My point, then, is that if you combine #once (or #pragma once) with
> traditional include guards, you get the best of all worlds.
But some compilers already implement the same semantics by remembering
that the include guards encompass the entire file. Why bother forcing
everyone to implement a special pragma when they can just do the same
thing?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: bop2@telia.com ("Bo Persson")
Date: Wed, 9 Apr 2003 05:06:09 +0000 (UTC) Raw View
"Allan W" <allan_w@my-dejanews.com> skrev i meddelandet
news:7f2735a5.0304081139.35985fb0@posting.google.com...
> jacob@jacob.remcomp.fr (jacob navia) wrote
> > > Will lcc-win32 include it twice, thus ignoring the #pragma once?
> >
> > Yes
> >
> > > If so, isn't that a bug?
> >
> > No. It is a network misconfiguration.
>
> It depends on the stated purpose of #once (or #pragma once).
>
> I view it as an optimization. A failed optimization is only a bug if it
> causes the wrong results.
>
> #define-style include guards have been around since the earliest days
> of C programming. They're easy to write, easy to understand, and they
> work very well (given a good naming standard). I teach this to
> first-year C++ students.
>
> #define-style include guards do have one shortcoming: in order for the
> compiler to skip an already-seen include guard, it has to re-open the
> source file, read the appropriate #if statement, scan for the matching
> #endif, and finally close the file. While this does not result in any
> sort of error, it can slow down the compile process.
No, it does not.
The compiler can remember files it has already seen, together with their
include guards. When it encounters another inlude of the same file, it can
check if the guard condition is still active, and skip the file entirely.
> #pragma once is an attempt to optimize the performance by skipping the
> file read when it is unneccesary. If this optimization fails, the program
> is still correct (but it compiles more slowly).
But, unless the compiler knows which files contain #pragma once (unguarded
pragrnas!), it still have to open and close the file.
> My point, then, is that if you combine #once (or #pragma once) with
> traditional include guards, you get the best of all worlds.
>
Sounds like you get neither...
Bo Persson
bop2@telia.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: jacob@jacob.remcomp.fr (jacob navia)
Date: Tue, 8 Apr 2003 08:32:11 +0000 (UTC) Raw View
> No, #pragma once just provokes different bugs. The bugs that #pragma
> once provokes relate to the use of relative paths, symlinks, hard links,
> network file systems, etc.
>
No!
If your setup is so messy that you are never sure if two different absolute
file paths point to different data you can ALWAYS use
#ifndef
#endif
#pragma once is NOT obligatory you see? Lcc-win32 will continue to support
the old ways.
> What does lcc-win32 do if the same file is included twice, via different
names
> that end up referring to the same file (e.g. via Samba, where two file
> names on the Linux file server may refer to the same file)?
Will read the file twice.
If you want to be 100% sure that in all possible network configurations your
file will be included only once just write a little more.
For all others, that have never seen (and do not want to see) such a messy
network config pleeeezee...
> Will lcc-win32 include it twice, thus ignoring the #pragma once?
Yes
> If so, isn't that a bug?
No. It is a network misconfiguration.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]