c89

File won't compile in MS Visual Studio, but will in GCC. Why?

对着背影说爱祢 提交于 2021-01-29 17:44:43
问题 I wrote such sample code: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> char* print_errno_msg(int value); int main(void){ struct stat buffer; int status; status = stat("./main.c", &buffer); char *msg = print_errno_msg(errno); /* syntax error : missing ';' before 'type' */ printf("status = %i; errno = %i; %s\n", status, errno, msg); /* 'msg' : undeclared identifier */ errno = 0; int ch = getchar(); /* syntax error : missing ';' before

What are the semantics of function pointers with empty parentheses in each C standard?

佐手、 提交于 2021-01-28 08:22:28
问题 Answers to this and this question say that function pointers of the form return-type (*pointer)() are pointers to a function which takes any number of arguments, though the latter says they obsolesced in C11. On an i386 system with GCC, “extra” arguments passed in a call to an empty-parentheses-type’d function pointer are ignored, because of how stack frames work; e.g., /* test.c */ #include <stdio.h> int foo(int arg) { return arg; } int main(void) { int (*fp)() = foo; printf("%d\n", fp

How standard is the {0} initializer in C89?

喜欢而已 提交于 2020-08-22 03:00:21
问题 In my current project, which uses the MISRA 2004 standard, we use three GCC compilers, versions 3.2.3, 4.4.2 and 5.4.0. We run build checks with the pedantic switch and c89 standard and a load of other restrictions. One of the restrictions is that all data must be initialised at declaration. I have a problem in that on GCC 3.2.3, the universal zero initialiser {0} only compiles for arrays of the basic unitary types. If I have an array of structs, then I get a missing braces warning and the

Was `long` guaranteed to be as wide as `size_t`

让人想犯罪 __ 提交于 2020-03-01 05:16:12
问题 When looking for evidence of unsigned long being enough to hold size_t for the purpose of being argument to printf I ran into two fact(oid)s. First there's this answer stating that long is indeed not guaranteed to be large enough for size_t . On the other hand I saw this answer suggesting to use printf("%lu", (unsigned long)x) in pre C99, x being of size_t . So the question is could you assume or were you guaranteed that long were enough to hold size_t in pre C99 . The other question is

Was `long` guaranteed to be as wide as `size_t`

僤鯓⒐⒋嵵緔 提交于 2020-03-01 05:16:09
问题 When looking for evidence of unsigned long being enough to hold size_t for the purpose of being argument to printf I ran into two fact(oid)s. First there's this answer stating that long is indeed not guaranteed to be large enough for size_t . On the other hand I saw this answer suggesting to use printf("%lu", (unsigned long)x) in pre C99, x being of size_t . So the question is could you assume or were you guaranteed that long were enough to hold size_t in pre C99 . The other question is

Was `long` guaranteed to be as wide as `size_t`

前提是你 提交于 2020-03-01 05:15:09
问题 When looking for evidence of unsigned long being enough to hold size_t for the purpose of being argument to printf I ran into two fact(oid)s. First there's this answer stating that long is indeed not guaranteed to be large enough for size_t . On the other hand I saw this answer suggesting to use printf("%lu", (unsigned long)x) in pre C99, x being of size_t . So the question is could you assume or were you guaranteed that long were enough to hold size_t in pre C99 . The other question is