Search:

Type: Posts; User: Drogin

Page 1 of 5 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    3
    Views
    2,142

    Great answer :) I noticed that they do check if...

    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...
  2. Replies
    3
    Views
    2,142

    aliasing in nginx code?

    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) ...
  3. Replies
    4
    Views
    1,087

    Wide use of virtual functions

    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"...
  4. Replies
    3
    Views
    13,168

    popen thread safe?

    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...
  5. Replies
    2
    Views
    9,290

    redirect STDOUT to pipes

    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...
  6. Thread: ++ vs +1

    by Drogin
    Replies
    3
    Views
    1,002

    Hehe, sorry about that, it struck me as I was...

    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?
  7. Thread: ++ vs +1

    by Drogin
    Replies
    3
    Views
    1,002

    ++ vs +1

    What do you think is the best, this:


    test = (++test) % 10;


    or this?


    test = (test +1) % 10;
  8. Replies
    14
    Views
    2,180

    I know of the atomic setting and checking of a...

    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...
  9. Replies
    14
    Views
    2,180

    I think is is very close to what I was asking: ...

    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?
  10. Replies
    14
    Views
    2,180

    That is what I'm asking :) Is there...

    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...
  11. Replies
    14
    Views
    2,180

    Aha, so you are saying function-calls are natural...

    Aha, so you are saying function-calls are natural compiler barriers that prevents compiler-optimization reordering?
  12. Replies
    14
    Views
    2,180

    I might not have understood you correctly, but...

    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...
  13. Replies
    14
    Views
    2,180

    threads and synchronization

    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...
  14. Thread: socket send

    by Drogin
    Replies
    8
    Views
    2,850

    On the opengroup-page for the recv() function,...

    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()...
  15. Thread: socket send

    by Drogin
    Replies
    8
    Views
    2,850

    OS is Redhat Linux. The code failing: ...

    OS is Redhat Linux.

    The code failing:


    void fail(void) {
    if(!(client->isConnected)) {
    fprintf(stderr,"Error, you are not connected to server\n");
    return;
    }
  16. Thread: socket send

    by Drogin
    Replies
    8
    Views
    2,850

    socket send

    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...
  17. Replies
    10
    Views
    2,145

    Writing struct to file

    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:

    ...
  18. Thread: ceil mystery

    by Drogin
    Replies
    2
    Views
    1,589

    Damn...no, I wasnt :D I knew there would be...

    Damn...no, I wasnt :D
    I knew there would be something basic I had forgotten to do.
  19. Thread: ceil mystery

    by Drogin
    Replies
    2
    Views
    1,589

    ceil mystery

    #include <math.h>
    #include <string.h>

    int main(void) {
    double test = (double) strlen("TEST");
    double test2 =(double) ceil(test);
    return 0;
    }
  20. Thread: NULL-pointers

    by Drogin
    Replies
    2
    Views
    1,233

    NULL-pointers

    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:

    ...
  21. Replies
    7
    Views
    2,085

    error reading file

    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...
  22. Replies
    6
    Views
    2,161

    If I wanted to represent 4 characters with only 2...

    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...
  23. Thread: void* pointers

    by Drogin
    Replies
    6
    Views
    3,983

    That is exactly what it is. No way. ...

    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++) {
  24. Thread: void* pointers

    by Drogin
    Replies
    6
    Views
    3,983

    Ah, so this code are only swapping elements of an...

    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...
  25. Thread: void* pointers

    by Drogin
    Replies
    6
    Views
    3,983

    void* pointers

    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;
    }
Results 1 to 25 of 105
Page 1 of 5 1 2 3 4