Search:

Type: Posts; User: KCfromNC

Page 1 of 14 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    19
    Views
    1,834

    Don't confuse fewer lines of C code with fast. ...

    Don't confuse fewer lines of C code with fast. Worst case (the array isn't in cache) this will be much slower than a loop or some of the other tricks mentioned above.
  2. If there's no restrictions in the homework, you...

    If there's no restrictions in the homework, you could do this using memmove().
  3. Replies
    8
    Views
    1,261

    Pretty close, but more likely here is that GCC is...

    Pretty close, but more likely here is that GCC is able to optimize some calls to math lib functions away completely when you pass in constants. Not sure why the second case can't be optimized away...
  4. Replies
    29
    Views
    2,270

    Yep. Probably easiest if the for loop runs from...

    Yep. Probably easiest if the for loop runs from 'a' to 'z', inclusive, and either keep a separate counter for the number of letters printed so far or realize that value is the current letter minus...
  5. Replies
    27
    Views
    2,065

    Not minimizing the work you guys have done to...

    Not minimizing the work you guys have done to figure this out, but notice that the professor's "optimization" requirements have changed what could have been simple straight-line floating point code...
  6. Replies
    9
    Views
    1,207

    Modern versions of GCC have -Ofast as an option. ...

    Modern versions of GCC have -Ofast as an option. You could try this as an alternative to -O3 and see if it does anything different.
  7. Wouldn't the most efficient implementation use...

    Wouldn't the most efficient implementation use something like scalbn() or ldexp()? It isn't the answer the HW is looking for, but it isn't the student's fault if the teacher asks the wrong question...
  8. Replies
    6
    Views
    1,082

    Another way to do this : # Use variables...

    Another way to do this :



    # Use variables for the target ($@ = demo here) and the dependencies ($^ = main.o f1.o f2.o)
    demo : main.o f1.o f2.o
    gcc -o $@ $^

    # Define a generic...
  9. Replies
    10
    Views
    2,411

    On certain x86 hardware and OS combinations,...

    On certain x86 hardware and OS combinations, maybe. Even on systems using x87 code, it could still depend on whether the code is FPU bound or memory bound. And even taking that into account, using...
  10. Replies
    12
    Views
    2,932

    You're getting a pointer, not an array. This is a...

    You're getting a pointer, not an array. This is a perfectly valid function call :

    unsigned char foo = 0xAB;
    shift(&foo, sizeof(foo));

    Or a variable can end up being more than 2 bytes :
    ...
  11. Replies
    6
    Views
    1,036

    make each entry of your stack a void * and a...

    make each entry of your stack a void * and a variable identifying the type. Create push_char_array and push_int functions - each mallocs space for the appropriate var, copies it into this space,...
  12. Replies
    10
    Views
    4,142

    llvm-gcc is a front end for LLVM based on gcc...

    llvm-gcc is a front end for LLVM based on gcc 4.2.x (where I can't remember the x). That puts it as older than the 4.3 needed to have the __COUNTER__ macro added to gcc. Clang is a gcc-alike front...
  13. Replies
    2
    Views
    545

    Link the application against a static version of...

    Link the application against a static version of the library. The details of how to do this vary by compiler and OS, so we'll need more information to help you.
  14. Or it will be 12 bytes or 16 bytes or maybe 4...

    Or it will be 12 bytes or 16 bytes or maybe 4 bytes, or something totally different. It very rarely matters - and usually then it only matters when you're doing something you shouldn't. When it...
  15. Replies
    3
    Views
    816

    Replace 4 * 2 * level / 10 with 4 + 2 * level/10.

    Replace 4 * 2 * level / 10 with 4 + 2 * level/10.
  16. Replies
    3
    Views
    816

    The bigger question is whether or not the...

    The bigger question is whether or not the original code is more correct that either of the simplifications listed in the thread.

    But another approach is a to have a lookup table of base values...
  17. The compiler isn't guaranteed to allocate memory...

    The compiler isn't guaranteed to allocate memory for them in the first place - they could be stored in registers, replaced by a constant in an opcode, or removed entirely if they are dead code - so...
  18. Which is balanced by the number of tasks you...

    Which is balanced by the number of tasks you eliminate by looping up to the sqrt rather than up to n/2. It's not like mod of an arbitrary integer is a cost-free operation in itself, so if you...
  19. Replies
    32
    Views
    21,409

    Only if you're talking about code size. If...

    Only if you're talking about code size. If you're interested in speed, the only real way to know is to run and time each example.
  20. Replies
    28
    Views
    2,588

    Yes, that's why you should be testing using a...

    Yes, that's why you should be testing using a loop. First test 3 as a factor and add 2 each time through the loop. Exit the loop when you've passed the sqrt of p. That way if p is large enough...
  21. How many cereal box tops do I need to send in to...

    How many cereal box tops do I need to send in to get this?
  22. I studied main carefully, as the directions say. ...

    I studied main carefully, as the directions say. This should pass all the test cases provided.



    /* The spec says that the result of this function is never used, so it's a NOP */
    void...
  23. Replies
    13
    Views
    1,485

    All versions? How far back do you want to go?...

    All versions? How far back do you want to go? Windows 1.0? Windows 95?
  24. Replies
    29
    Views
    2,201

    I'm not sure how one loop is going to run faster...

    I'm not sure how one loop is going to run faster than the other when any reasonable compiler is going to remove those loops as dead code anyway. I wonder if he was trying to test how fast the code...
  25. Replies
    13
    Views
    1,485

    You'll need to ask the right question - do you...

    You'll need to ask the right question - do you want to run on all machines or just on all Windows machines? Those are two very different goals.
Results 1 to 25 of 344
Page 1 of 14 1 2 3 4