c99

What is an efficient way to convert a bignum type structure to a human readable string?

喜你入骨 提交于 2019-12-03 16:47:44
I've got a bit of a problem. In order to grow in my knowledge of C, I've decided to try to implement a basic bigint library. The core of the bigint structure will be an array of 32 bit integers, chosen because they will fit in a register. This will allow me to do operations between digits that will overflow in a 64 bit integer (which will also fit in a register, as I'm on x86-64), and I can bitshift out each part of the result. I've implemented basic addition, and to test that it is working, I have to print the array. For my own testing purposes, it's fine if I use printf() and output each

Are zero-length variable length arrays allowed/well defined?

风流意气都作罢 提交于 2019-12-03 15:21:34
I'm programming in C99 and use variable length arrays in one portion of my code. I know in C89 zero-length arrays are not allowed, but I'm unsure of C99 and variable length arrays. In short, is the following well defined behavior? int main() { int i = 0; char array[i]; return 0; } No, zero-length arrays are explicitly prohibited by C language, even if they are created as VLA through a run-time size value (as in your code sample). 6.7.5.2 Array declarators ... 5 If the size is an expression that is not an integer constant expression: if it occurs in a declaration at function prototype scope, it

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

How to get into C99 mode in Codeblocks10.05?

一世执手 提交于 2019-12-03 14:20:44
I recently realized that I am not even in C99 mode after receiving the compile error 'for' loop initial declarations are only allowed in C99 mode I found some advice on how to get to C99 via a quick search which has told me to go to Projects -> Properties... But alas, it is greyed out and I am not sure that is even the correct way to fix it (probably not available because my file is not a project, it is a normal source file). I have also seen a lot of similar questions saying to enable C99 mode so I have looked inside the compiler flags menu, but I cannot see anything about C99. I have tried

Variadic macros with 0 arguments in C99

六月ゝ 毕业季﹏ 提交于 2019-12-03 12:49:37
I have some debugging code that looks like the following: #define STRINGIFY(x) #x #define TOSTRING(x) STRINGIFY(x) #define AT __FILE__ ":" TOSTRING(__LINE__) void __my_error(const char*loc, const char *fmt, ...); #define my_error(fmt, ...) __my_error(AT, fmt, ##__VA_ARGS__) The last macro is used so I can insert the location into the debug output as to where the error occurred. However, when I call the function like this: my_error("Uh oh!"); I would like my code to be C99, so I find when this compiles, I get the following error: error: ISO C99 requires rest arguments to be used I know I can

Optimizing linear access to arrays with pre-fetching and cache in C

余生颓废 提交于 2019-12-03 11:00:45
disclosure: I've tried similar question on programmers.stack, but that place is nowhere near activity stack is. Intro I tend to work with lots of large images. They also come in sequences of more than one and have to be processed and played back repeatedly. Sometimes I use GPU, sometimes CPU, sometimes both. Most of access patterns are linear in nature (back and forth) which got me thinking about more basic things regarding arrays and how should one approach writing code optimized for maximum memory bandwidth possible on given hardware (permitting computation isn't blocking read/write). Test

How do you configure GCC in Eclipse to use C99?

帅比萌擦擦* 提交于 2019-12-03 10:24:54
I'm working on a small C project in Eclipse; I just installed Eclipse from the Ubuntu Software Center and added C/C++ Language Support. I can build, run, and debug simple C programs fine. But I'm using some C99 features now, and Eclipse complains, saying "'for' loop initial declarations are only allowed in C99 mode". I thought you'd set C99 mode for GCC in the makefile, but the makefile is auto-generated by Eclipse so any changes I make would be overwritten, but I don't see anywhere to put GCC compiler options anywhere in Eclipse's preferences nor my Project Properties windows. So where do I

Lifetime of temporary objects in C11 vs C99

主宰稳场 提交于 2019-12-03 10:05:11
I am trying to decipher a note that led to a change between C99 and C11. The change proposed in that note ended up in C11's 6.2.4:8, namely: A non-lvalue expression with structure or union type, where the structure or union contains a member with array type (including, recursively, members of all contained structures and unions) refers to an object with automatic storage duration and temporary lifetime. Its lifetime begins when the expression is evaluated and its initial value is the value of the expression. Its lifetime ends when the evaluation of the containing full expression or full

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

Can a C compiler change bit representation when casting signed to unsigned?

喜欢而已 提交于 2019-12-03 07:42:33
问题 Is it possible for an explicit cast of, say, int32_t to uint32_t , to alter the bit representation of the value? For example, given that I have the following union: typedef union { int32_t signed_val; uint32_t unsigned_val; } signed_unsigned_t; Are these code segments guaranteed by the spec to have the same behaviour? uint32_t reinterpret_signed_as_unsigned(int32_t input) { return (uint32_t) input; } and uint32_t reinterpret_signed_as_unsigned(int32_t input) { signed_unsigned_t converter;