c89

Is it undefined behavior to exceed translation limits and are there checker tools to find it?

不羁的心 提交于 2020-01-01 04:35:06
问题 ORIGINAL QUESTION: I'm searching the C90 standard for things to be aware of, when writing hignly portable code, while having low trust in the good will of the compiler vendor, and assuming that my software might kill somebody sometimes, if I do things wrong. Let's say I'm a little paranoid. At the moment I am thinking about the "Translation limits" (5.2.4.1 ANSI/ISO 9899:1990). As pointed out in the standard and in: "Does ansi C place a limit on the number of external variables in a program?"

Portable C SWAP macro which doesn't require a 'type' argument and doesn't use memcpy

孤街浪徒 提交于 2019-12-30 12:57:07
问题 Swap macro's which take a type are fairly well known. #define SWAP(type, a_, b_) do { \ type SWAP, *a = &(a_), *b = &(b_); \ SWAP = *a; \ *a = *b; \ *b = SWAP; \ } while (0) also: Macro SWAP(t,x,y) exchanging two arguments of type t Is it possible to implement this functionality while being... portable (no compiler specific typeof ) without using function calls such as memcpy (which isn't assured to get optimized out, it wasn't in my tests at least ) I came up with a flawed method which uses

strtol using errno

…衆ロ難τιáo~ 提交于 2019-12-30 11:33:11
问题 I have the following code: #include <stdlib.h> #include <stdio.h> #include <errno.h> void main(void) { int data; char * tmp; data = strtol("23ef23",&tmp,10); printf("%d",errno); getchar(); } output is 0 ... why? i am using visual studio 2010 C++ code must be C89 compatible. 回答1: strtol only sets errno for overflow conditions, not to indicate parsing failures. For that purpose, you have to check the value of the end pointer, but you need to store a pointer to the original string: char const *

strtol using errno

妖精的绣舞 提交于 2019-12-30 11:33:05
问题 I have the following code: #include <stdlib.h> #include <stdio.h> #include <errno.h> void main(void) { int data; char * tmp; data = strtol("23ef23",&tmp,10); printf("%d",errno); getchar(); } output is 0 ... why? i am using visual studio 2010 C++ code must be C89 compatible. 回答1: strtol only sets errno for overflow conditions, not to indicate parsing failures. For that purpose, you have to check the value of the end pointer, but you need to store a pointer to the original string: char const *

C89, Mixing Variable Declarations and Code

回眸只為那壹抹淺笑 提交于 2019-12-29 06:26:06
问题 I'm very curious to know why exactly C89 compilers will dump on you when you try to mix variable declarations and code, like this for example: rutski@imac:~$ cat test.c #include <stdio.h> int main(void) { printf("Hello World!\n"); int x = 7; printf("%d!\n", x); return 0; } rutski@imac:~$ gcc -std=c89 -pedantic test.c test.c: In function ‘main’: test.c:7: warning: ISO C90 forbids mixed declarations and code rutski@imac:~$ Yes, you can avoid this sort of thing by staying away from -pedantic.

Warning: this decimal constant is unsigned only in ISO C90

早过忘川 提交于 2019-12-28 05:21:06
问题 Piece of code : long rangeVar = 0; rangeVar = atol(p_value); if (rangeVar >= -2147483648 && rangeVar <= 2147483647) On compiling I get: warning: this decimal constant is unsigned only in ISO C90 Thanks in Advance 回答1: The rules for the types of decimal integer constants changed between the 1990 and 1999 editions of the ISO C standard. In the 1990 version, an unsuffixed decimal integer constant's type is the first of int , long int , or unsigned long int in which its value can be represented.

Where can I find the C89/C90 standards in PDF format? [closed]

自闭症网瘾萝莉.ら 提交于 2019-12-28 04:39:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm looking for a free copy version of the C89/C90 standard, but I can't find it anywhere! Why is so hard to find it? C99 and C11 standards are very easy to get a copy of on Internet. Even in Stack Overflow question Where do I find the current C or C++ standard documents? and in The C Standard, Obtaining the

What does (void)var actually do?

跟風遠走 提交于 2019-12-28 04:04:24
问题 Consider the following main() : int main(int argc, char *argv[]) { return (0); } Upon compilation with cc -Wall -Wextra , warnings saying "unused parameter" get generated. When I do not need to use a parameter in a function (for instance in a signal handler function that makes no use of its int parameter), I am used to doing the following: int main(int argc, char *argv[]) { (void)argc; (void)argv; return (0); } (For that particular main() , I sometimes see other people do: argv = argv - argc

What does (void)var actually do?

五迷三道 提交于 2019-12-28 04:04:20
问题 Consider the following main() : int main(int argc, char *argv[]) { return (0); } Upon compilation with cc -Wall -Wextra , warnings saying "unused parameter" get generated. When I do not need to use a parameter in a function (for instance in a signal handler function that makes no use of its int parameter), I am used to doing the following: int main(int argc, char *argv[]) { (void)argc; (void)argv; return (0); } (For that particular main() , I sometimes see other people do: argv = argv - argc

Type to use to represent a byte in ANSI (C89/90) C?

孤街浪徒 提交于 2019-12-27 17:37:21
问题 Is there a standards-complaint method to represent a byte in ANSI (C89/90) C? I know that, most often, a char happens to be a byte, but my understanding is that this is not guaranteed to be the case. Also, there is stdint.h in the C99 standard, but what was used before C99? I'm curious about both 8 bits specifically, and a "byte" (sizeof(x) == 1). 回答1: char is always a byte , but it's not always an octet . A byte is the smallest addressable unit of memory (in most definitions), an octet is 8