Hi,
I am about to make some changes to an existing Apache C module to fix some possible security flaws and general bad practices. However the functionality of the code must remain unchanged (except in cases where its fixing a bug). Standard regression testing stuff seems to be in order. I would like to know if anyone knows of a good wa...
What is a generic list manipulation function in C?
(I saw this when I was going through some materials.)
What is the difference between this function and a function which can accept elements of any kind?
Are they same...? How can we implement them individually if they are not same?
...
What is forward reference in C with respect to pointers?
Can I get an example?
...
The Daily WTF for 2008-11-28 pillories the following code:
static char *nice_num(long n)
{
int neg = 0, d = 3;
char *buffer = prtbuf;
int bufsize = 20;
if (n < 0)
{
neg = 1;
n = -n;
}
buffer += bufsize;
*--buffer = '\0';
do
{
*--buffer = '0' + (n % 10);
n /= 10;
...
I'm compiling some MATLAB functions into a C DLL. The exported mlf functions return a boolean value representing whether the function succeeded or not. When the return value is false, I want to find out the error information. I couldn't find a way to do that! (other than compiling and exporting the lasterror() function).
Is there a C in...
How would I calculate a time period between 2 dates using C (any library, etc.). For example the program would take two (local) dates and would spit out the period duration between them. For example startDate = oct-9-1976 and endDate = oct-9-2008 would show a duration of 32 years OR startDate = oct-9-1976 and endDate = dec-9-2008 would s...
How to list physical disks in windows?
In order to obtain a list of "\.\PhysicalDrive0" available.
...
I have a multi file C program. I'd like the user to be able to specify different debugging levels at run time.
What is the best way to implement this?
I was thinking of having a debug(level, "message") type function exported and used everywhere. Any better/other ideas?
...
I have a structure:
struct pkt_
{
double x;
double y;
double alfa;
double r_kw;
};
typedef struct pkt_ pkt;
A table of these structures:
pkt *tab_pkt;
tab_pkt = malloc(ilosc_pkt * sizeof(pkt));
What I want to do is to sort tab_pkt by tab_pkt.alfa and tab_pkt.r:
qsort(tab_pkt, ilosc_pkt, sizeof(pkt), porownaj);
Where po...
I was hanging out in my profiler for a while trying to figure out how to speed up a common log parser which was bottlenecked around the date parsing and I tried various algorithms to speed things up.
The thing I tried that was fastest for me was also by far the most readable, but potentially non-standard C.
This worked quite well in gc...
The execvp() function executes the program that is given as an argument. It checks the $PATH variable to find the program. I'm writing something in which I would like to check to see if several programs exist before calling any exec() functions. What's the best way to do this?
...
There's a lot of conflicting information about this topic. So let's try to agree on a definitive answer:
Which one of these random number generator in C create better randomness: rand, random or arc4random?
note: Just to make the question clear, this is not a question about true randomness, it's only a clash between those 3.
As poin...
Hi!
Just wondering if there is any way (in C) to get the contents of the console buffer, preferably as some kind of char array. It is going to be written to a file, so if I am missing out on something stupid that will do exactly that, then point it out. It can be Windows-specific. I am using MinGW (gcc 3.4.5).
Thanks in advance.
...
I'm looking to learn some fundamentals on cartesian geometry or coordinates based game programming. Platform is irrelevant, although I'm most proficient in JavaScript, C, Objective-C. Ultimately being able to create something such as dots or checkers would be ideal. The idea is for me to learn how sprites work and how pathing works progr...
Hi,
Is there a reason why zero is used as a "default" function return value? I noticed that several functions from the stdlib and almost everywhere else, when not returning a proper number (e.g pow(), strcpy()) or an error (negative numbers), simply return zero.
I just became curious after seeing several tests performed with negated log...
As per c99 standard, size of "long long" should be minimum 64 bits. How this is implemented in a 32 bit machine(eg. addition or multiplication of 2 "long long"s).
What is the equivalent of long long in C++.
...
Hi guys!
I'm not a specialist for ANSI C (or regular C at all), so I stumbled about this stupid thing:
I want to initialize a struct element, splitted in declaration and initialization. This is what I got:
typedef struct MY_TYPE {
boolean flag;
short int value;
double stuff;
} MY_TYPE;
void function(void) {
MY_TYPE a;
...
...
In C the following horror is valid:
myFunc()
{
return 42; // return type defaults to int.
}
But, what about in C++? I can't find a reference to it either way...
My compiler (Codegear C++Builder 2007) currently accepts it without warning, but I've had comments that this is an error in C++.
...
I have a piece of code in ANSI C which uses the time.h library and time_h structures to (amongst other date-related calculations) work out the interval between two given dates. This works fine but this limits my code to input between 1970 and 2038. I would now like to make my code more general.
Is there a common C library (ANSI or C99 s...
I realize that this question is impossible to answer absolutely, but I'm only after ballpark figures:
Given a reasonably sized C-program (thousands of lines of code), on average, how many ASM-instructions would be generated. In other words, what's a realistic C-to-ASM instruction ratio? Feel free to make assumptions, such as 'with curre...