c99

Avoid duplicating code

Hi all, let's say I have: switch( choice ) { case A: stmt; do_stmt_related2A; break; case B: stmt; do_stmt_related2B; break; case C: something_different(); ... } How could I avoid duplicating stmt code? But is there any workaround? gcc extension label as value looks quite good for such situa...

Dealing with ctype.h integer overflow

What is the proper way to deal with character values which when casted to an unsigned char fall between {INT_MAX + 1 ... UCHAR_MAX} where UCHAR_MAX is greater than INT_MAX. int is_digit(char c) { unsigned char uchar = c; if(uchar > INT_MAX) return MAYBE; return isdigit((int)uchar) ? YES : NO; } ...

Type for array index in C99

What type for array index in C99 should be used? It have to work on LP32, ILP32, ILP64, LP64, LLP64 and more. It doesn't have to be a C89 type. There are 5 candidates: size_t ptrdiff_t intptr_t / uintptr_t int_fast*_t / uint_fast*_t int_least*_t / uint_least*_t There is simple code to better illustrate problem. What is the best type...

Anonymous union within struct not in c99?

Hi, here is very simplified code of problem I have: enum node_type { t_int, t_double }; struct int_node { int value; }; struct double_node { double value; }; struct node { enum node_type type; union { struct int_node int_n; struct double_node double_n; }; }; int main(void) { struct int_no...

Why isn't regular expressions part of ISO C99

Everyone knows how awesome C language is and how much it sucks in text processing tasks. Given these facts. Regex definitely must be part of ISO C. But it isn't. I don't understand why? Are there people who think its not essential? ...

How to get involved in C standardization process?

Hello, Lately I've been getting interest in C standardization. I want to participate in development of C1X. I want to put forward my ideas (irrespective of they being accepted/rejected). I want to know the procedure. WG14 documents shows various documents sorted by mailing list. Where can I join one such mailing list? How to submit a p...

How to implement and share an inlined function using C99 ?

With gnu89: /* share.h */ extern inline void f (void); /* function.c */ void f (void) {} /* main.c */ #include "share.h" int main (int argc, char **argv) { f (); return 0; } With C99: /* share.h */ static inline void f (void) {} /* main.c */ #include "share.h" int main (int argc, char **argv) { f (); return 0; } ...

Reallocating an array (C99)

The standard specifies that the contents of reallocated space is undefined if the new size if larger. If preserving the contents of the previously-allocated space is important, is the best way to reallocate data as follows: copying it to the stack, freeing it from the heap, allocating on the heap with more space, and copying back to the...

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

Hello all, 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 integ...

complex number types in mixing C(99) and C++

I'm writing a math library, the core of it is in C++. Later it may be implemented in pure C (C99 I suppose). I think I need a C like API so that I can get Python and matlab and the like to use the library. My impression is that doing this with C++ is painful. So is there a good or standard or proper way to cast between double complex *s...

C99 Macro to build a quoted string literal after evaluation

I'm developing an embedded application in C99, and the project contains some integer constants defined like: #define LEVEL1 0x0000 #define LEVEL2 (LEVEL1 + 1) It has since become useful to keep track of these values for logging purposes, so I would like to use a macro to create a string literal from the evaluated versions of t...

C type casts and addition precedence

What's the precedence in the next expression? item = (char*)heap + offset; Is it (char*)(heap + offset) or ((char*)heap) + offset? ...

unistd.h and c99 on Linux

This simple .c file: #include <unistd.h> void test() { char string[40]; gethostname(string,40); } ... when compiled normally, works fine: $ cc -Wall -c -o tmp.o tmp.c $ ... but when compiled in C99 mode, gives a warning: $ cc -Wall -std=c99 -c -o tmp.o tmp.c tmp.c: In function `test': tmp.c:5: warning: implicit declaratio...

What does this compiler warning generated by `-pedantic` mean?

What does this GCC warning mean? cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used The relevant lines are: __attribute__((format(printf, 2, 3))) static void cpfs_log(log_t level, char const *fmt, ...); #define log_debug(fmt, ...) cpfs_log(DEBUG, fmt, ##__VA_ARGS__) log_debug("Resetting bitmap"); The last line bei...

Optimizing 'for-loops' over arrays in C99 with different indexing.

Hi there, I want to speed up an array multiplication in C99. This is the original for loops: for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { total[j]+= w[j][i] * x[i]; } } My boss asked my to try this, but it did not improve the speed: for(int i=0;i<n;i++) { float value = x[i]; for(int...

Why do the authors of the C/C99 standard, don't specify a ..standard for the sizeof floating point types?

I noticed on windows and linux x86, float is 4bytes, double is 8, but long double is 12 and 16 on x86 and x86_64 respectively. C99 is supposed to be breaking such barriers with the specific integral sizes. The initial technological limitation appears to be due to the x86 processor not being able to handle more than 80bit floating operat...

C99 fenv.h for MS compilers

Anyone know of a decent C99 fenv.h implementation for MS compilers? I imagine this wouldn't be difficult to do; I'm just looking to save some time. ...

Micro-optimizations: using intptr_t for flag/bool types.

From what I understand, the definition of intptr_t varies by architecture -- it is guaranteed to have the capacity to represent a pointer that can access all of the uniform address space of a process. Nginx (popular open source web-server) defines a type that is used as a flag(boolean) and this a typedef to intptr_t. Now using the x86-6...

How to format text output in c

How do i change the font size etc. In c99 ...

Implicit declaration in C

Does the following program invoke Undefined Behaviour in C? int main() { printf("Printf asking: Where is my declaration ?"); } In the above program there is an implicit declaration of printf(), so is the above code fully standard compliant or it just has some implementation specific behaviour? ...