POV-Ray : Newsgroups : povray.general : POV Includes note : Re: POV Includes note Server Time
8 Aug 2024 22:10:08 EDT (-0400)
  Re: POV Includes note  
From: Peter J  Holzer
Date: 29 Sep 2000 18:01:22
Message: <slrn8t9tdl.r5e.hjp-usenet@teal.h.hjp.at>
On 29 Sep 2000 08:49:11 -0400, Geoff Wedig wrote:
>Does POV make sure it hasn't already included a particular include?

No. But see below.

>I think not, or a lot of the include file style functions wouldn't work
>multiple times.

Yes.

>Parsing a long include of essentially just definitions (even if they
>overwrite only themselves) could take quite a bit of time, if it's a
>long file.
>
>So there is some use in checking to see if a particular include (not of
>the type where including multiple times can have different results) has
>already been included.

In C the standard way to avoid including files twice has always been
to put something like

#ifndef __this_file_INCLUDED__
    #define __this_file_INCLUDED__

    ...

#endif

around the whole file. If you look at colors.inc, you can see that
povray uses a similar technique.

However, while this prevents any untoward effects of redeclaring
variables, and speeds up the parsing of the file quite a bit, it doesn't
normally prevent the compiler (or povray) from parsing the file a second
(and third, fourth, ...) time, so it isn't as fast as it could be.

Gcc uses two tricks to prevent that:

Firstly, it introduced a directive #import, which was similar to
#include, but would do nothing if the file had already been imported.
Being gcc-specific, this didn't help programs designed to be portable
and is rarely used. Povray doesn't have this problem, so this solution
might be viable for povray.

Secondly, the compiler[1] checks whether the include file conforms to
the #ifndef MACRO; #define MACRO; ...; #endif layout, and if it does,
it won't include the file again if MACRO is defined. This is a bit more
complicated but helps existing scene files. (But if someone want's to
implement this, DON'T take the code from cccp, the GPL is incompatible
with povray's license).

	hp

[1] Actually the preprocessor, cccp.

-- 

|_|_) | Sysadmin WSR       | vor dem rechner.

__/   | http://www.hjp.at/ |       at.linux, 2000-09-24


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.