Great answer :)
I noticed that they do check if you're on x86_64 before defining this macro... so I guess it's not directly dangerous. But is it valid code according to the C standard? Do you know...
Type: Posts; User: Drogin
Great answer :)
I noticed that they do check if you're on x86_64 before defining this macro... so I guess it's not directly dangerous. But is it valid code according to the C standard? Do you know...
I'm pondering a bit about the code I'm seeing in nginx...:confused:
It's a code for checking if a string equals a sequence of characters:
#define ngx_str3_cmp(m, c0, c1, c2, c3) ...
I'm learned C and C++ first, and only learned java because my university required me to do so. Other people at my university learned Java first, and to me, they have a very typical "Java mindset"...
Is popen safe to use with pthreads?
I've tried to google it, but I found no straight answer.
And in forums, some people claim it's not because it forks, while others say it's considered...
Hey,
I'm trying to redirect stdout, so it goes into a pipe, so I can do something like this:
printf("Hey there!\n");
then read from the pipe and get "Hey there!".
The code I'm trying to use...
Hehe, sorry about that, it struck me as I was reading my post a second time ;)
But now it should be correct, so is one of those alternatives in my first post a more correct way than the other?
What do you think is the best, this:
test = (++test) % 10;
or this?
test = (test +1) % 10;
I know of the atomic setting and checking of a variable, ususally done with xchng instruction on X86, and basic mutex theory and usage.
What I was wondering of, was how to avoid compiler level...
I think is is very close to what I was asking:
So, I guess this must be included in lock() and unlock(), then I should be atleast safe from compiler reordering, yes?
That is what I'm asking :)
Is there something(like a memory fence instruction in x86) I can put inside the lock / unlock functions in my mutex, to prevent the compiler-optimizer from moving...
Aha, so you are saying function-calls are natural compiler barriers that prevents compiler-optimization reordering?
I might not have understood you correctly, but stick with me and see if this addresses your previous post:
In this article:
Volatile: Almost Useless for Multi-Threaded Programming – Intel Software...
Hi everyone.
Let's say I am to make my own mutex, lets call it lock / unlock.
Then have the following code:
(And please, this is only a very c-looking pseudo-code. Don't bother saying how the...
On the opengroup-page for the recv() function, they specify that if it reads 0, it means the connection is lost.
But about send(), all it says is this:
Successful completion of a call to send()...
OS is Redhat Linux.
The code failing:
void fail(void) {
if(!(client->isConnected)) {
fprintf(stderr,"Error, you are not connected to server\n");
return;
}
I got a little problem with a server / client, using TCP.
If I start my server, then start my client, all is good.
My client and server finds out if they "Loose connection", by checking...
I has read that when writing a whole struct to a file with fwrite() is bad, as it's nonportable.
But does it change anything to write the whole struct with fputc() ?
Something like this:
...
Damn...no, I wasnt :D
I knew there would be something basic I had forgotten to do.
#include <math.h>
#include <string.h>
int main(void) {
double test = (double) strlen("TEST");
double test2 =(double) ceil(test);
return 0;
}
Hey!
I have just malloc'd a chunk of memory for a struct with various members.
Some of those members is pointers.
I want to check if the pointer isnt given a value by doing so:
...
If I'm trying to read untill end of file, using fgets(), and somewhere inside the loop, let's say fgets fails. (Which means we got a read-error).
What would be the most correct thing to do if that...
If I wanted to represent 4 characters with only 2 bits, I have two alternatives:
#1:
To use a struct with 2 bitfields
#2:
To use 1 char to store 2 characters, using bit-manipulation
And...
That is exactly what it is.
No way.
char array[3]; // Array of 3 chars
// Set all elements to 0
int i;
for(i=0; i > 3; i++) {
Ah, so this code are only swapping elements of an array of *void pointers..?
If so, that sure helps.
The book had just written about how void* can be used to point to all kinds of types, so I...
I have this mysterious code...
void swap(void *v[], int i, int j) {
void *temp;
temp = v[i];
v[i] = v[j];
v[j] = temp;
}