Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #58664

Re: multiple header includes

From Richard Heathfield <rjh@cpax.org.uk>
Newsgroups comp.lang.c
Subject Re: multiple header includes
Date 2015-03-22 13:10 +0000
Organization go, ion artisan!
Message-ID <memevd$foi$1@dont-email.me> (permalink)
References <mem3vs$6io$1@speranza.aioe.org>

Show all headers | View raw


On 22/03/15 10:02, jeff wrote:
> although in most cases we see the good practises of Header Guards, is
> there a risk for some architectures, that code like this,
> #include<stdio.h>
> #include<stdio.h>
> (eg same header included twice), will invoke an Undefined Behavior?

The Standard requires that multiple inclusion of standard headers will 
be fine. "Standard headers may be included in any order; each may be 
included more than once in a given scope, with no effect different from 
being included only once, except that the effect of including <assert.h> 
depends on the definition of NDEBUG" - clear enough, I think.

I suppose implementors make this possible in the usual way - i.e. be 
careful what you define in a header, and use inclusion guards:

#ifndef H_MYHEADER_H
#define H_MYHEADER_H 1
header stuff goes here
#endif

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

multiple header includes jeff <nospam@nospam.com> - 2015-03-22 10:02 +0000
  Re: multiple header includes Lőrinczy Zsigmond <nospam@for.me> - 2015-03-22 11:14 +0100
  Re: multiple header includes Richard Heathfield <rjh@cpax.org.uk> - 2015-03-22 13:10 +0000
  Re: multiple header includes Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-22 08:12 -0700
  Re: multiple header includes Robbie Hatley <see.my.sig@for.my.address> - 2015-03-27 02:46 -0700
    Re: multiple header includes James Kuyper <jameskuyper@verizon.net> - 2015-03-27 09:32 -0400
      Re: multiple header includes Robbie Hatley <see.my.sig@for.my.address> - 2015-04-11 14:08 -0700
        Re: multiple header includes Keith Thompson <kst-u@mib.org> - 2015-04-11 19:49 -0700
    Re: multiple header includes Keith Thompson <kst-u@mib.org> - 2015-03-27 08:32 -0700
  Re: multiple header includes fir <profesor.fir@gmail.com> - 2015-04-12 11:35 -0700
    Re: multiple header includes fir <profesor.fir@gmail.com> - 2015-04-12 11:45 -0700
      Re: multiple header includes fir <profesor.fir@gmail.com> - 2015-04-12 11:58 -0700

csiph-web