c

What is the best way to learn C? What next after K&R?

I am able to program in Lisp, Python, Ruby, JavaScript and Prolog and I have been willing to learn how to program in C for a very long time now. I know the syntax and basic concepts (I've actually read Kernigham & Ritchie), but I've never been able to pass through the writing “Hello world!” stage. So, my problem is related not to the l...

which tools are helpful in determining the cyclomatic complexity of a given C source code

I want to know which tool can be used to measure the cyclomatic complexity of a C source. I have seen other post which ask the same question but I want to know specific tool for C source only. ...

Refactoring global to local. Should they be static or not?

I'm refactoring "spaghetti code" C module to work in multitasking (RTOS) environment. Now, there are very long functions and many unnecessary global variables. When I try to replace global variables that exists only in one function with locals, I get into dilemma. Every global variable is behave like local "static" - e.g. keep its valu...

fork() as an argument

Usually when I need to fork in C, I do something like this: pid_t p = fork(); if(p == 0) { /* do child stuff */ } else { /* do parent stuff and pray there wasn't an error */ } It occured to me that I could ditch the extra variable and use: if(fork() == 0) { /* child */ } else { /* parent/pray */ } Improper error handling aside, (wh...

#ifdef vs #if - which is better/safer?

This may be a matter of style, but there's a bit of a divide in our dev team and I wondered if anyone else had any ideas on the matter... Basically, we have some debug print statements which we turn off during normal development. Personally I prefer to do the following: \\---- SomeSourceFile.cpp ---- #define DEBUG_ENABLED (0) ... So...

Reading 32bit Packed Binary Data On 64bit System

I'm attempting to write a Python C extension that reads packed binary data (it is stored as structs of structs) and then parses it out into Python objects. Everything works as expected on a 32 bit machine (the binary files are always written on 32bit architecture), but not on a 64 bit box. Is there a "preferred" way of doing this? ...

How to preserve stack space with good design?

I'm programming in C for RAM limited embedded microcontroller with RTOS. I regularly break my code to short functions, but every function calling require to more stack memory. Every task needs his stack, and this is one of the significant memory consumers in the project. Is there an alternative to keep the code well organized and reada...

Will pthread_detach manage my memory for me?

Suppose I have the following code: while(TRUE) { pthread_t *thread = (pthread_t *) malloc(sizeof(pthread_t)); pthread_create(thread, NULL, someFunction, someArgument); pthread_detach(*thread); sleep(10); } Will the detached thread free the memory allocated by malloc, or is that something I now have to do? ...

What happens when you try to free() already freed memory in c?

For example: char * myString = malloc(sizeof(char)*STRING_BUFFER_SIZE); free(myString); free(myString); Are there any adverse side effects of doing this? ...

Difference between Enum and Define Statements

What's the difference between using a define statement and an enum statement in C/C++? (and is there any difference when using them with either C or C++?) For example, when should one use enum {BUFFER = 1234}; over #define BUFFER 1234 Thanks ...

Why don't I see a significant speed-up when using the MATLAB compiler?

I have a lot of nice MATLAB code that runs too slowly and would be a pain to write over in C. The MATLAB compiler for C does not seem to help much, if at all. Should it be speeding execution up more? Am I screwed? ...

How do you get assembler output from C/C++ source in gcc?

How does one do this? If I want to analyze how something is getting compiled, how would I get the emitted assembly code? ...

In C (and C++) is it considered bad form to use comparison operators outside of conditionals?

For example int f(int a) { ... return a > 10; } is that considered acceptable (not legal, I mean is it ``good code''), or should it always be in a conditional, like this int f(int a) { ... if (a > 10) return 1; else return 0; } ...

How to use POP3 over SSL in C

I would like to know and understand the steps involved in fetching mail from pop3 server using plain c language ...

ncurses in windows

please list a ncurses libraries in C/C++ for windows that emulate ncurses in native resizable win32 windows NOT in console mode. ...

difference in speed between char and integer arrays?

Hello all, currently I'm dealing with a video processing software in which the picture data (8bit signed and unsigned) is stored in arrays of 16-aligned integers allocated as __declspec(align(16)) int *pData = (__declspec(align(16)) int *)_mm_malloc(width*height*sizeof(int),16); Generally, wouldn't it enable faster reading and writing...

Is it feasible to compile Python to machine code?

How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code? Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves would need to be compiled (and linked in) too. Also, you would need to bundle the Python in...

How universally is C99 supported ?

How universally is the C99 standard supported in today's compilers ? I understand that not even GCC fully supports it. Is this right ? Which features of C99 are supported more than others, i.e. which can I use to be quite sure that most compilers will understand me ? Thanks ...

Should Local Variable Initialisation Be Mandatory?

The maintenance problems that uninitialised locals cause (particularly pointers) will be obvious to anyone who has done a bit of c/c++ maintenance or enhancement, but I still see them and occasionally hear performance implications given as their justification. It's easy to demonstrate in c that redundant initialisation is optimised out:...

How do you manipulate GUID's when doing Windows programming in C or C++?

How do you manipulate GUID's when doing Windows programming in C or C++? Thanks to Rich B for fixing my "faux pas" and moving my reply to my own question out of the question itself and into a standalone answer. ...