Header file that includes all standard C library headersReverse all lines in a fileMakefile and main header...
Simulating a probability of 1 of 2^N with less than N random bits
How will losing mobility of one hand affect my career as a programmer?
How can I raise concerns with a new DM about XP splitting?
Can you use Azure DevOps with Sitecore Managed Cloud
Organic chemistry Iodoform Reaction
Can I use my Chinese passport to enter China after I acquired another citizenship?
Latex for-and in equation
Can a malicious addon access internet history and such in chrome/firefox?
Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?
How can I successfully establish a nationwide combat training program for a large country?
The most efficient algorithm to find all possible integer pairs which sum to a given integer
Can a Gentile theist be saved?
Could solar power be utilized and substitute coal in the 19th century?
Bob has never been a M before
Calculating the number of days between 2 dates in Excel
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
How can a jailer prevent the Forge Cleric's Artisan's Blessing from being used?
Can I rely on these GitHub repository files?
I2C signal and power over long range (10meter cable)
Indicating multiple different modes of speech (fantasy language or telepathy)
Perfect riffle shuffles
Can a Bard use an arcane focus?
Greatest common substring
Is there a problem with hiding "forgot password" until it's needed?
Header file that includes all standard C library headers
Reverse all lines in a fileMakefile and main header file for a shellLibrary for manipulation of binary protocol headersStandard way of reading file contents to a bufferShort header file for safe CLI input handling in CImplementation of C Standard Library Function ntohl()Sending instructions to an LCD display controlled by HD44780C library for standard input operations with data validation and error checkPortability in using up-and-coming library featuresPortably get one character from standard input using standard library only
$begingroup$
The Standard C Library consists of various headers files. Often only a few select ones are needed for given code.
Other times it is simply convenient coding to include them all in a .c file, even if that make the compilation time a bit slower.
Including all standard <*.h>
is useful to help detect naming collisions of a .c
file with an existing standard function, object, type, macro, etc.
Review Goal
How well does std.h
accomplish the goal of including all standard header files via one .h
file given that the set varies amongst C versions and implementations?
/*
* std.h
* Created on: Mar 16, 2019, Author: chux
*/
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif
#endif /* STD_H_ */
In making a set of functions and types called say foo
, I do not recommend including all header files in a foo.h
, yet perhaps in foo.c
.
Sample usage
// foo.h (no std.h here)
#ifndef FOO_H_
#define FOO_H_
#include <stdint.h>
#include <time.h>
typedef struct {
time_t t;
uint32_t u32;
} foo;
void foo_this(foo *f);
void foo_that(foo *f);
#endif /* FOO_H_ */
foo.c
or main.c
#include "foo.h"
#include "std.h"
int main(void) {
foo f;
foo_this(&f);
foo_that(&f);
printf("Hello World!n");
return 0;
}
The alternative spellings afforded in <iso646.h>
seem to be a solution to a regional character set problem of years ago. I reluctantly included <iso646.h>
here but do see that a good candidate to exclude. It defines macros for and
, or
, xor
and others.
c portability
$endgroup$
add a comment |
$begingroup$
The Standard C Library consists of various headers files. Often only a few select ones are needed for given code.
Other times it is simply convenient coding to include them all in a .c file, even if that make the compilation time a bit slower.
Including all standard <*.h>
is useful to help detect naming collisions of a .c
file with an existing standard function, object, type, macro, etc.
Review Goal
How well does std.h
accomplish the goal of including all standard header files via one .h
file given that the set varies amongst C versions and implementations?
/*
* std.h
* Created on: Mar 16, 2019, Author: chux
*/
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif
#endif /* STD_H_ */
In making a set of functions and types called say foo
, I do not recommend including all header files in a foo.h
, yet perhaps in foo.c
.
Sample usage
// foo.h (no std.h here)
#ifndef FOO_H_
#define FOO_H_
#include <stdint.h>
#include <time.h>
typedef struct {
time_t t;
uint32_t u32;
} foo;
void foo_this(foo *f);
void foo_that(foo *f);
#endif /* FOO_H_ */
foo.c
or main.c
#include "foo.h"
#include "std.h"
int main(void) {
foo f;
foo_this(&f);
foo_that(&f);
printf("Hello World!n");
return 0;
}
The alternative spellings afforded in <iso646.h>
seem to be a solution to a regional character set problem of years ago. I reluctantly included <iso646.h>
here but do see that a good candidate to exclude. It defines macros for and
, or
, xor
and others.
c portability
$endgroup$
$begingroup$
When I read the title, I thought "but why?" Having read the description, I see what you're doing. However, beware that that if you contravene the naming rules - which I'm sure you don't - then finding no collisions using this compiler, today doesn't guarantee anything about other builds. Past success is no guarantee of future performance!
$endgroup$
– Toby Speight
15 hours ago
$begingroup$
@TobySpeight Agree the including all<*.h>
will not certainly detect all name collision and future ones, yet is a reasonable test today to potential discern them.
$endgroup$
– chux
14 hours ago
add a comment |
$begingroup$
The Standard C Library consists of various headers files. Often only a few select ones are needed for given code.
Other times it is simply convenient coding to include them all in a .c file, even if that make the compilation time a bit slower.
Including all standard <*.h>
is useful to help detect naming collisions of a .c
file with an existing standard function, object, type, macro, etc.
Review Goal
How well does std.h
accomplish the goal of including all standard header files via one .h
file given that the set varies amongst C versions and implementations?
/*
* std.h
* Created on: Mar 16, 2019, Author: chux
*/
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif
#endif /* STD_H_ */
In making a set of functions and types called say foo
, I do not recommend including all header files in a foo.h
, yet perhaps in foo.c
.
Sample usage
// foo.h (no std.h here)
#ifndef FOO_H_
#define FOO_H_
#include <stdint.h>
#include <time.h>
typedef struct {
time_t t;
uint32_t u32;
} foo;
void foo_this(foo *f);
void foo_that(foo *f);
#endif /* FOO_H_ */
foo.c
or main.c
#include "foo.h"
#include "std.h"
int main(void) {
foo f;
foo_this(&f);
foo_that(&f);
printf("Hello World!n");
return 0;
}
The alternative spellings afforded in <iso646.h>
seem to be a solution to a regional character set problem of years ago. I reluctantly included <iso646.h>
here but do see that a good candidate to exclude. It defines macros for and
, or
, xor
and others.
c portability
$endgroup$
The Standard C Library consists of various headers files. Often only a few select ones are needed for given code.
Other times it is simply convenient coding to include them all in a .c file, even if that make the compilation time a bit slower.
Including all standard <*.h>
is useful to help detect naming collisions of a .c
file with an existing standard function, object, type, macro, etc.
Review Goal
How well does std.h
accomplish the goal of including all standard header files via one .h
file given that the set varies amongst C versions and implementations?
/*
* std.h
* Created on: Mar 16, 2019, Author: chux
*/
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif
#endif /* STD_H_ */
In making a set of functions and types called say foo
, I do not recommend including all header files in a foo.h
, yet perhaps in foo.c
.
Sample usage
// foo.h (no std.h here)
#ifndef FOO_H_
#define FOO_H_
#include <stdint.h>
#include <time.h>
typedef struct {
time_t t;
uint32_t u32;
} foo;
void foo_this(foo *f);
void foo_that(foo *f);
#endif /* FOO_H_ */
foo.c
or main.c
#include "foo.h"
#include "std.h"
int main(void) {
foo f;
foo_this(&f);
foo_that(&f);
printf("Hello World!n");
return 0;
}
The alternative spellings afforded in <iso646.h>
seem to be a solution to a regional character set problem of years ago. I reluctantly included <iso646.h>
here but do see that a good candidate to exclude. It defines macros for and
, or
, xor
and others.
c portability
c portability
edited yesterday
200_success
130k17155419
130k17155419
asked yesterday
chuxchux
13.5k21345
13.5k21345
$begingroup$
When I read the title, I thought "but why?" Having read the description, I see what you're doing. However, beware that that if you contravene the naming rules - which I'm sure you don't - then finding no collisions using this compiler, today doesn't guarantee anything about other builds. Past success is no guarantee of future performance!
$endgroup$
– Toby Speight
15 hours ago
$begingroup$
@TobySpeight Agree the including all<*.h>
will not certainly detect all name collision and future ones, yet is a reasonable test today to potential discern them.
$endgroup$
– chux
14 hours ago
add a comment |
$begingroup$
When I read the title, I thought "but why?" Having read the description, I see what you're doing. However, beware that that if you contravene the naming rules - which I'm sure you don't - then finding no collisions using this compiler, today doesn't guarantee anything about other builds. Past success is no guarantee of future performance!
$endgroup$
– Toby Speight
15 hours ago
$begingroup$
@TobySpeight Agree the including all<*.h>
will not certainly detect all name collision and future ones, yet is a reasonable test today to potential discern them.
$endgroup$
– chux
14 hours ago
$begingroup$
When I read the title, I thought "but why?" Having read the description, I see what you're doing. However, beware that that if you contravene the naming rules - which I'm sure you don't - then finding no collisions using this compiler, today doesn't guarantee anything about other builds. Past success is no guarantee of future performance!
$endgroup$
– Toby Speight
15 hours ago
$begingroup$
When I read the title, I thought "but why?" Having read the description, I see what you're doing. However, beware that that if you contravene the naming rules - which I'm sure you don't - then finding no collisions using this compiler, today doesn't guarantee anything about other builds. Past success is no guarantee of future performance!
$endgroup$
– Toby Speight
15 hours ago
$begingroup$
@TobySpeight Agree the including all
<*.h>
will not certainly detect all name collision and future ones, yet is a reasonable test today to potential discern them.$endgroup$
– chux
14 hours ago
$begingroup$
@TobySpeight Agree the including all
<*.h>
will not certainly detect all name collision and future ones, yet is a reasonable test today to potential discern them.$endgroup$
– chux
14 hours ago
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
With this suggested usage:
#include "foo.h"
#include "std.h"
then any macros defined in "std.h"
(and not used in the rest of the main
) won't break the program. Swapping these round:
#include "std.h"
#include "foo.h"
solves that problem, but then fails to diagnose missing includes in "foo.h"
.
$endgroup$
add a comment |
$begingroup$
Your code doesn't cover "freestanding implementations" (embedded systems or OS). You could check for
#if __STDC_HOSTED__ == 0
and reduce the headers. Freestanding implementations need not provide all headers except a minimal subset, see C11 4/6:
A conforming freestanding implementation shall accept any strictly conforming program in which the
use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers<float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>,
and
<stdnoreturn.h>
Though of course freestanding implementations may provide other headers too, making this hard to fulfil without a specific implementation in mind.
Style issue: you should indent everything within
#if
...#endif
just as you would for regularif
statements. It is also good practice to leave a comment /* */ after each#endif
to document which#if
is belongs to.
EDIT: proposed indention fix
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif /* #if defined __STDC__ && defined __STDC_VERSION__ */
#endif /* STD_H_ */
$endgroup$
$begingroup$
Please post a sample#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and# if bar
which looks odd. Perhaps you have another?
$endgroup$
– chux
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216119%2fheader-file-that-includes-all-standard-c-library-headers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
With this suggested usage:
#include "foo.h"
#include "std.h"
then any macros defined in "std.h"
(and not used in the rest of the main
) won't break the program. Swapping these round:
#include "std.h"
#include "foo.h"
solves that problem, but then fails to diagnose missing includes in "foo.h"
.
$endgroup$
add a comment |
$begingroup$
With this suggested usage:
#include "foo.h"
#include "std.h"
then any macros defined in "std.h"
(and not used in the rest of the main
) won't break the program. Swapping these round:
#include "std.h"
#include "foo.h"
solves that problem, but then fails to diagnose missing includes in "foo.h"
.
$endgroup$
add a comment |
$begingroup$
With this suggested usage:
#include "foo.h"
#include "std.h"
then any macros defined in "std.h"
(and not used in the rest of the main
) won't break the program. Swapping these round:
#include "std.h"
#include "foo.h"
solves that problem, but then fails to diagnose missing includes in "foo.h"
.
$endgroup$
With this suggested usage:
#include "foo.h"
#include "std.h"
then any macros defined in "std.h"
(and not used in the rest of the main
) won't break the program. Swapping these round:
#include "std.h"
#include "foo.h"
solves that problem, but then fails to diagnose missing includes in "foo.h"
.
answered 15 hours ago
Toby SpeightToby Speight
26.6k742118
26.6k742118
add a comment |
add a comment |
$begingroup$
Your code doesn't cover "freestanding implementations" (embedded systems or OS). You could check for
#if __STDC_HOSTED__ == 0
and reduce the headers. Freestanding implementations need not provide all headers except a minimal subset, see C11 4/6:
A conforming freestanding implementation shall accept any strictly conforming program in which the
use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers<float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>,
and
<stdnoreturn.h>
Though of course freestanding implementations may provide other headers too, making this hard to fulfil without a specific implementation in mind.
Style issue: you should indent everything within
#if
...#endif
just as you would for regularif
statements. It is also good practice to leave a comment /* */ after each#endif
to document which#if
is belongs to.
EDIT: proposed indention fix
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif /* #if defined __STDC__ && defined __STDC_VERSION__ */
#endif /* STD_H_ */
$endgroup$
$begingroup$
Please post a sample#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and# if bar
which looks odd. Perhaps you have another?
$endgroup$
– chux
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
add a comment |
$begingroup$
Your code doesn't cover "freestanding implementations" (embedded systems or OS). You could check for
#if __STDC_HOSTED__ == 0
and reduce the headers. Freestanding implementations need not provide all headers except a minimal subset, see C11 4/6:
A conforming freestanding implementation shall accept any strictly conforming program in which the
use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers<float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>,
and
<stdnoreturn.h>
Though of course freestanding implementations may provide other headers too, making this hard to fulfil without a specific implementation in mind.
Style issue: you should indent everything within
#if
...#endif
just as you would for regularif
statements. It is also good practice to leave a comment /* */ after each#endif
to document which#if
is belongs to.
EDIT: proposed indention fix
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif /* #if defined __STDC__ && defined __STDC_VERSION__ */
#endif /* STD_H_ */
$endgroup$
$begingroup$
Please post a sample#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and# if bar
which looks odd. Perhaps you have another?
$endgroup$
– chux
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
add a comment |
$begingroup$
Your code doesn't cover "freestanding implementations" (embedded systems or OS). You could check for
#if __STDC_HOSTED__ == 0
and reduce the headers. Freestanding implementations need not provide all headers except a minimal subset, see C11 4/6:
A conforming freestanding implementation shall accept any strictly conforming program in which the
use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers<float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>,
and
<stdnoreturn.h>
Though of course freestanding implementations may provide other headers too, making this hard to fulfil without a specific implementation in mind.
Style issue: you should indent everything within
#if
...#endif
just as you would for regularif
statements. It is also good practice to leave a comment /* */ after each#endif
to document which#if
is belongs to.
EDIT: proposed indention fix
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif /* #if defined __STDC__ && defined __STDC_VERSION__ */
#endif /* STD_H_ */
$endgroup$
Your code doesn't cover "freestanding implementations" (embedded systems or OS). You could check for
#if __STDC_HOSTED__ == 0
and reduce the headers. Freestanding implementations need not provide all headers except a minimal subset, see C11 4/6:
A conforming freestanding implementation shall accept any strictly conforming program in which the
use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers<float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>,
and
<stdnoreturn.h>
Though of course freestanding implementations may provide other headers too, making this hard to fulfil without a specific implementation in mind.
Style issue: you should indent everything within
#if
...#endif
just as you would for regularif
statements. It is also good practice to leave a comment /* */ after each#endif
to document which#if
is belongs to.
EDIT: proposed indention fix
#ifndef STD_H_
#define STD_H_
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined __STDC__ && defined __STDC_VERSION__
#if __STDC_VERSION__ >= 199409
#include <iso646.h>
#include <wchar.h>
#include <wctype.h>
#endif
#if __STDC_VERSION__ >= 199901
#ifndef __STDC_NO_COMPLEX__
#include <complex.h>
#endif
#include <fenv.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#endif
#if __STDC_VERSION__ >= 201112
#include <stdalign.h>
#ifndef __STDC_NO_ATOMICS__
#include <stdatomic.h>
#endif
#include <stdnoreturn.h>
#ifndef __STDC_NO_THREADS__
#include <threads.h>
#endif
#include <uchar.h>
#endif
#if __STDC_VERSION__ >= 201710
/* None added */
#endif
#endif /* #if defined __STDC__ && defined __STDC_VERSION__ */
#endif /* STD_H_ */
edited 13 hours ago
answered 14 hours ago
LundinLundin
1,862823
1,862823
$begingroup$
Please post a sample#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and# if bar
which looks odd. Perhaps you have another?
$endgroup$
– chux
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
add a comment |
$begingroup$
Please post a sample#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and# if bar
which looks odd. Perhaps you have another?
$endgroup$
– chux
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
$begingroup$
Please post a sample
#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and # if bar
which looks odd. Perhaps you have another?$endgroup$
– chux
13 hours ago
$begingroup$
Please post a sample
#
indent. I have tried various styles, ` #if bar` (my auto formatter (Eclipse) keeps shifting them left ) and # if bar
which looks odd. Perhaps you have another?$endgroup$
– chux
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
$begingroup$
@chux Posted. After trying some 30+ different, magic IDEs including GNU indent, I'm convinced that mankind will never develop intelligent AI. So I tend to fall back to good ole spacebar :)
$endgroup$
– Lundin
13 hours ago
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216119%2fheader-file-that-includes-all-standard-c-library-headers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
When I read the title, I thought "but why?" Having read the description, I see what you're doing. However, beware that that if you contravene the naming rules - which I'm sure you don't - then finding no collisions using this compiler, today doesn't guarantee anything about other builds. Past success is no guarantee of future performance!
$endgroup$
– Toby Speight
15 hours ago
$begingroup$
@TobySpeight Agree the including all
<*.h>
will not certainly detect all name collision and future ones, yet is a reasonable test today to potential discern them.$endgroup$
– chux
14 hours ago