c89

How to enforce C89-style variable declarations in gcc?

本小妞迷上赌 提交于 2019-12-03 16:59:03
问题 I work on a code base which is mostly C with a little C++, and is mostly built with gcc but occasionally it needs to be built with MSVC. Microsoft's C compiler is still pretty much C89 with a few minor extensions, and it still doesn't support mixed code and variable definitions à la C++/C99. So I need to find a way to prevent developers from writing out-of-order code/variable definitions while they are working with gcc, otherwise the build subsequently breaks with MSVC. If I use gcc -std=c89

How to use make and compile as C99?

时光怂恿深爱的人放手 提交于 2019-12-03 15:14:17
问题 I'm trying to compile a linux kernel module using a Makefile: obj-m += main.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Which gives me: main.c:54: warning: ISO C90 forbids mixed declarations and code I need to switch to C99. After reading I noticed I need to add a flag -std=c99, not sure where it suppose to be added. How do I change the Makefile so it will compile as C99? 回答1: It's got nothing to do

Typesafe varargs in C with gcc

无人久伴 提交于 2019-12-03 09:51:30
Many times I want a function to receive a variable number of arguments, terminated by NULL, for instance #define push(stack_t stack, ...) _push(__VARARG__, NULL); func _push(stack_t stack, char *s, ...) { va_list args; va_start(args, s); while (s = va_arg(args, char*)) push_single(stack, s); } Can I instruct gcc or clang to warn if foo receives non char* variables? Something similar to __attribute__(format) , but for multiple arguments of the same pointer type. I know you're thinking of using __attribute__((sentinel)) somehow, but this is a red herring. What you want is to do something like

A good C equivalent of STL vector?

ぃ、小莉子 提交于 2019-12-03 08:50:36
问题 I've noticed that at several places in our code base we use dynamically expanding arrays, i.e. a base array coupled with an element counter and a "max elements" value. What I want to do is replace these with a common data structure and utility functions, for the usual object-oriented reasons. The array elements can be either basic data types or structs, I need fast random access to the elements, and preferably a type-safe implementation. So, basically, what I would like to use is an STL

Are all of the features of C99 also in C++?

元气小坏坏 提交于 2019-12-03 08:11:21
问题 This page lists 53 features that were new in C99 (i.e they are in C99 but not C89). Are all of these features also in C++? Even C++98? If not, which of the features are in C++ and which are not? 回答1: The following C99 (ISO 9899:1999) features are fully supported by C++ (ISO 14882:2017): (though library headers will be <cname> rather than <name.h> : wide character library support in <wchar.h> and <wctype.h> (originally specified in ISO/IEC 9899:1990/Amd.1:1995) type-generic math macros in

A way to convert byte stream to packet stream in C89 on an embedded device [closed]

谁说胖子不能爱 提交于 2019-12-03 07:28:17
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I’m working on with an embedded device that is connected to PC using rs232 (rs232 over USB). I’m thinking about developing my own

How to enforce C89-style variable declarations in gcc?

老子叫甜甜 提交于 2019-12-03 06:02:47
I work on a code base which is mostly C with a little C++, and is mostly built with gcc but occasionally it needs to be built with MSVC. Microsoft's C compiler is still pretty much C89 with a few minor extensions, and it still doesn't support mixed code and variable definitions à la C++/C99. So I need to find a way to prevent developers from writing out-of-order code/variable definitions while they are working with gcc, otherwise the build subsequently breaks with MSVC. If I use gcc -std=c89 then everything breaks because C++-style comments are not allowed (there may be other issues too, but I

Is it legal and well defined behavior to use a union for conversion between two structs with a common initial sequence (see example)?

妖精的绣舞 提交于 2019-12-03 05:13:31
I have an API with a publicly facing struct A and an internal struct B and need to be able to convert a struct B into a struct A. Is the following code legal and well defined behavior in C99 (and VS 2010/C89) and C++03/C++11? If it is, please explain what makes it well-defined. If it's not, what is the most efficient and cross-platform means for converting between the two structs? struct A { uint32_t x; uint32_t y; uint32_t z; }; struct B { uint32_t x; uint32_t y; uint32_t z; uint64_t c; }; union U { struct A a; struct B b; }; int main(int argc, char* argv[]) { U u; u.b.x = 1; u.b.y = 2; u.b.z

How to use make and compile as C99?

主宰稳场 提交于 2019-12-03 04:51:32
I'm trying to compile a linux kernel module using a Makefile: obj-m += main.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Which gives me: main.c:54: warning: ISO C90 forbids mixed declarations and code I need to switch to C99. After reading I noticed I need to add a flag -std=c99, not sure where it suppose to be added. How do I change the Makefile so it will compile as C99? It's got nothing to do with the makefile. ISO C90 forbids declaring variables anywhere but in the beginning of a block or the file -

How does the below program output `C89` when compiled in C89 mode and `C99` when compiled in C99 mode?

北慕城南 提交于 2019-12-03 01:06:24
问题 I've found this C program from the web: #include <stdio.h> int main(){ printf("C%d\n",(int)(90-(-4.5//**/ -4.5))); return 0; } The interesting thing with this program is that when it is compiled and run in C89 mode, it prints C89 and when it is compiled and run in C99 mode, it prints C99 . But I am not able to figure out how this program works. Can you explain how the second argument of printf works in the above program? 回答1: C99 allows // -style comments, C89 does not. So, to translate: C99: