Header file that includes all standard C library headers
$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$
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 1 hour ago
200_success
130k17155419
130k17155419
asked 8 hours ago
chuxchux
13.5k21345
13.5k21345
add a comment |
add a comment |
0
active
oldest
votes
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
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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