c

Ignoring SIGCHLD in some cases but not others

In my program, I fork() several times depending on user input. In certain instances, I want to handle SIGCHLD and say something like "Process # Finished". In other cases though, I want to ignore this signal. How can I do this? ...

snprintf Format String security vulnerability issue

We have a Coverity bug for this line of code: snprintf( tempStr, size, testStrings[testID], A2DtoV(testResults[testID].value), A2DtoV(testResults[testID].min),A2DtoV(testResults[testID].max)); The error says: non_const_printf_format_string: "format string is not a string literal, potential security vulnerability if user controlled" ...

Library initialization -- pthread_once in Win32 implementation

Hello. I am trying to make a fully thread-safe initialization function for my library and I couldn't easily find an alternative to pthread_once, which should solve the problem very easily. I've come to this code: void libInit (void) { #ifdef WIN32 static volatile int initialized = 0; static HANDLE mtx; if (!initialized) ...

C/C++ Free alternative to Lint?

I'm interested in a free tool that can statically check my C++ code like Lint does. Any hints? ...

C over C++

In what situation would C be a better language to work with than C++. I guess since I'm young and wasn't brought up on C like others were, so I have no clue why people tend to still use C these days when C++ is now available? What advantages does C offer that keep people still wanting to stick to it? ...

What is the feasibility of porting a legacy C program to Python?

I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange. Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned? ...

clearing a char array c

Hello, I thought by setting the first element to a null would clear the entire contents of a char array. char my_custom_data[40] = "Hello!"; my_custom_data[0] = '\0'; However, this only sets the first element to null. or my_custom_data[0] = 0; rather than use memset, I thought the 2 examples above should clear all the data. Many...

Better way to forward declare typedef'd structures in C89?

struct SomeStruct; typedef struct SomeStruct SomeStruct; The above works, but is there a simpler (or better) way? ...

c library for computing mean, median, mode, other statistics?

Are there any c (or c++) libraries out there that can take an array of numbers and do basic statistical analysis on it (mean, median, mode, whatever else might be interesting)? ...

What is the signature of printf ?

Recently in an interview I was asked about what the signature of printf is. I really couldn't get a right answer. Would someone be able to shed some light on this? ...

Automatic Entry Exit trace in C

Do i have to add entry and exit logs in all the C functions? If, so are there any possible ways to write the entry and exit of a function automatically (Similar to Automatic Entry/Exit using Aspect oriented Programming in java). The application that I'm writing is time critical and adding entry/exit statements for each function might...

How to determine the state of a process (i.e. if it is a zombie)

Hi, how can I get information on the state of a process (i.e. if it is a zombie) using C under Linux? After reading the answers so far I want to narrow my question somewhat: I would prefer a pure C solution. After reading the ps source (which reads /proc/) I thought that there should be a better way and asked here :) ...

Please help me understand SQL vs C like programming?

Specifically I am trying to grasp how SQL statements differ from normal C style programming, I can't seem to understand how to do stuff like "for every userid in this table that has another column of data equal to such and such, run this stored procedure" which in programming would be a for loop, how the heck do you do stuff like that? ...

A good bank of solved recursion problems in C/C++/Java/C#

I saw this question, but the answers there are not very relevant. A friend needs a bank of solved recursion problems to help him study for a test tomorrow. He learned the issue theoretically, but is having problems grasping how to actually solve recursion problems. Do you know a good source of solved recursion problems (preferably in C,...

Best Language for String Manipulation?

I am about to begin writing an app that handles adding new users/repostories to my subversion server, so that I don't have to repeatedly open vi and edit conf files and execute shell commands. Most of my experience centers around C, C++, Objective-C and Java. Java seems decent for string manipulations with its tokenizer class, however I...

Advice for a C, CUDA, & ANN Newbie?

I'm a business major, two-thirds of the way through my degree program, with a little PHP experience, having taken one introductory C++ class, and now regretting my choice of business over programming/computer science. I am interested in learning more advanced programming; specifically C, and eventually progressing to using the CUDA arch...

Why does glibc "timezone" global not agree with system time on DST?

I'm experiencing a bizarre issue where my system clock knows that it's daylight savings time, but glibc seems not to. This is an up-to-date Ubuntu installation, and I have checked /etc/localtime and it has the correct changeover time for last week's switch to DST. The current correct timezone for me is Pacific Daylight Time (UTC-7). Whe...

Concept of WNDCLASSEX, good programming habits and WndProc for system classes

I understand that the Windows API uses "classes", relying to the WNDCLASS/WNDCLASSEX structures. I have successfully gone through windows API Hello World applications and understand that this class is used by our own windows, but also by Windows core controls, such as "EDIT", "BUTTON", etc. I also understand that it is somehow related t...

What is the point of saying "#define FOO FOO" in C?

I came across some C code where the author uses the following idiom all over the place: typedef __int32 FOO_INT32; #define FOO_INT32 FOO_INT32 What is the point of doing this? Shouldn't the typedef be enough? It is a workaround for some wonky C compilers out there? ...

What's the best programming language to use on a sucky computer?

I have a computer with 128 MB's of RAM (I said it was a piece of crap). It runs Windows XP Professional (slugishly). I don't have to use this computer except at night time when I'm supposed to be in bed, around 1:00 - 4:00 AM. So what is the best programming language / compiler to use? Which is the least RAM dependent. ...