c99

Is it possible to generate ansi C functions with type information for a moving GC implementation?

半腔热情 提交于 2021-02-07 10:35:28
问题 I am wondering what methods there are to add typing information to generated C methods. I'm transpiling a higher-level programming language to C and I'd like to add a moving garbage collector. However to do that I need the method variables to have typing information, otherwise I could modify a primitive value that looks like a pointer. An obvious approach would be to encapsulate all (primitive and non-primitive) variables in a struct that has an extra (enum) variable for typing information,

How enable c99 mode in gcc with terminal

删除回忆录丶 提交于 2021-02-06 10:14:46
问题 I want to activate c99 mode in gcc compiler to i read in other post in this forum that -std should be equal to -std=c99 but i don't know how to set it to this value using command line so please help. 回答1: Compile using: gcc -std=c99 -o outputfile sourcefile.c gcc --help lists some options, for a full list of options refer to the manual. The different options for C dialect can be found here. As you are using make you can set the command line options for gcc using CFLAGS : # sample makefile CC

Dynamic array on stack (VLA) vs heap performance

瘦欲@ 提交于 2021-01-29 22:18:37
问题 Most of the time we can assume that stack is faster and cleaner. No memory fragmentation, easier to cache, quick allocation. That's also why people always assume that static buffer allocated on stack is much faster than dynamic buffer on heap. Is it? One misconception I see most of the time is that people assume that c99 extension (which is supported as non-standard extension in common C++ compilers like GCC) allocating dynamic sized array on stack will perform as fast as static size. I think

func() vs func(void) in c99

Deadly 提交于 2021-01-29 17:38:29
问题 void func() In practice, an empty parameter means any argument is accepted. void func(void) accepts no argument. But in Standard C99, I find such lines: 6.7.5.3 Function declarators (including prototypes) 14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition

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

Passing a function as an argument in OpenCL

谁都会走 提交于 2021-01-27 19:52:39
问题 Is it possible to pass a function pointer to a kernel in OpenCL 1.2? I know it can be done in C, but I don't know how to do it in OpenCL's C. Edit: I would like to do the same thing that is described in this post: How do you pass a function as a parameter in C?, but to a kernel. Previously, I have used inline functions to call them from a kernel, but I want the function to be a parameter instead of hard coded in. 回答1: Short: OpenCL's C != C, consider it as a syntactical help that most of it

GCC warning me about directive output truncation

白昼怎懂夜的黑 提交于 2021-01-27 12:36:05
问题 I've been compiling with clang for a while, but now that I'm back with GCC (8.3), I'm getting a lot of non-fatal warnings. For example, I have the following line of code that prints a given longitude, in a fixed-width format "(degrees)(minutes).(seconds)(W|E)". Before this, though, I have code that calculates degrees , minutes , and seconds while making sure that all values are sane (e.g., that -90 ≤ degrees ≤ 90 no matter what). So this compiles and runs perfectly: snprintf(pResult, 10, "

How should I obtain the fractional part of a floating-point value?

≯℡__Kan透↙ 提交于 2021-01-27 12:16:26
问题 I have a variable x of type float , and I need its fractional part. I know I can get it with x - floorf(x) , or fmodf(x, 1.0f) My questions: Is one of these always preferable to the other? Are they effectively the same? Is there a third alternative I might consider? Notes: If the answer depends on the processor I'm using, let's make it x86_64, and if you can elaborate about other processors that would be nice. Please make sure and refer to the behavior on negative values of x . I don't mind

Why does clang complain about using variable-length arrays with '-std=c99' flag?

久未见 提交于 2021-01-27 06:35:12
问题 When I compile this experiment code: int main(void) { int foo = 5; char bar[foo]; } with clang and the '-Weverything' or respectively the separate '-Wvla' flag combined with the '-std=c99' flag, I still get the warning: warning: variable length array used [-Wvla] Example here although C99 conform implementations shall, in comparison to later C standards (C11, C18, etc.) - where the VLA-support is optional, support variable length arrays without exception. Why do I still get this warning for