Search:

Type: Posts; User: tretton

Page 1 of 2 1 2

Search: Search took 0.01 seconds.

  1. Replies
    1
    Views
    1,265

    Static variables in functions

    As a sort of lame approach to explaining static variables in functions to noobs (like myself), could you say that, FOR THE FUNCTION IN QUESTION, the following:


    void func(void)
    {
    static int...
  2. Replies
    5
    Views
    1,455

    Whitespaces before macro bracket

    I believe I read somewhere that you should always align the preprocessor # in the first column, but now I'm having trouble verifying my sources. I googled, but didn't find any real good info. Is...
  3. Replies
    8
    Views
    3,269

    Yes, you are correct. My brain isn't working...

    Yes, you are correct. My brain isn't working tonight. I rest my case.
  4. Replies
    8
    Views
    3,269

    Alright, I actually didn't read your post very...

    Alright, I actually didn't read your post very thoroughly... :P But seriously, all odd years are leap years? Are we talking leap years as in an extra day in February? 'Cause I thought that was...
  5. Replies
    8
    Views
    3,269

    Watch your indentation! if (year%8 == 0 &&...

    Watch your indentation!


    if (year%8 == 0 && year%32 != 0){
    if(year%2 == 1)
    printf("\n%d is a leap year", year);
    }
    else
    printf("\n%d is not a leap year", year);
  6. Thread: Dina!

    by tretton
    Replies
    12
    Views
    2,851

    Dina was indeed pretty neat! Thanks! ...

    Dina was indeed pretty neat! Thanks!

    Code::Blocks + Dina 8pt :)
  7. Replies
    19
    Views
    3,240

    void changeMe(char param[]) { param =...

    void changeMe(char param[])
    {
    param = "World!";
    }

    I'm not an expert, but I would say that you are just telling the local pointer param to point to the read-only string "World!". This...
  8. Thread: Which compiler

    by tretton
    Replies
    15
    Views
    2,144

    Anyone tried the CodeBlocks IDE...

    Anyone tried the CodeBlocks IDE (http://www.codeblocks.org)? It's an open source IDE written in C++, which also uses MinGW as its default compiler (but can use several others). Anyone still using...
  9. Thread: Splint

    by tretton
    Replies
    24
    Views
    3,871

    Are you guys serious? I mean, it compiles without...

    Are you guys serious? I mean, it compiles without a single warning, it's just Splint that is a bit stingy. The prototype for pow() is double pow(double b, double p), so if I have two ints, a and b,...
  10. Thread: Splint

    by tretton
    Replies
    24
    Views
    3,871

    I always cast when the compiler tells me too, but...

    I always cast when the compiler tells me too, but not otherwise. Splint wanted me to cast my ints to doubles when I passed them to pow(), but that's a bit too much overkill for me. I try to keep my...
  11. Thread: Splint

    by tretton
    Replies
    24
    Views
    3,871

    Splint

    What's your opinion on Splint and the likes? Should you use it, and how far should you go?

    My current program passes splint -weak with just a few adjustments, most of them including type casts....
  12. Replies
    14
    Views
    1,452

    The cpr2[4]=0; assigns the nul character (string...

    The cpr2[4]=0; assigns the nul character (string terminator) to the fifth (0, 1, 2, 3, 4) character in the string. You need the terminator since there is no other way of telling where the string ends.
  13. Replies
    14
    Views
    1,452

    Oh, yeah. But in this case, the semicolon is just...

    Oh, yeah. But in this case, the semicolon is just an empty statement that has nothing to do with the loop, right? Like:


    for (blabla) {}

    ;

    Not that it matters or anything.
  14. Replies
    14
    Views
    1,452

    The for loop must not end with a semicolon if...

    The for loop must not end with a semicolon if you're using braces:


    for(i=0; i<4; i++) {
    cpr2[i] = cpr1[i];
    }
  15. Replies
    14
    Views
    1,452

    And the semicolon: cpr2[i] = cpr1[i]; ;)

    And the semicolon:

    cpr2[i] = cpr1[i];

    ;)
  16. Replies
    13
    Views
    6,739

    True that. Now I'm freeing everything. I...

    True that. Now I'm freeing everything.

    I should have been more specific with that last question though, sorry about that. I meant all variables declared in the beginning of the function (int x,...
  17. Replies
    13
    Views
    6,739

    Wee, I admit defeat! Redesigning the function was...

    Wee, I admit defeat! Redesigning the function was of course trivial after a good night's sleep, and I basically went from:


    return create_exp(main_conn->conn, '\0', build_tree(start,...
  18. Replies
    13
    Views
    6,739

    Yes, I know it's lazy, but: (Quote from:...

    Yes, I know it's lazy, but:


    (Quote from: http://c-faq.com/malloc/freeb4exit2.html)

    And this is pretty much my case (maybe not overly complicated, but interconnected). I know I'm arguing about...
  19. Replies
    13
    Views
    6,739

    Freeing memory before exit

    I'm writing a small program which reads a single line of input, mallocs a bunch of structs, calculates and prints results and then exits. Should I free any mallocs just before the program exits (as...
  20. Replies
    2
    Views
    1,080

    For starters, I believe you're jumping off the...

    For starters, I believe you're jumping off the end of your array:


    SHORT Epos_X[4]; //Enemy position X, totals 5(C++ is 0 based)
    ...
    Epos_X[4] = 20;

    Zero based only means that they are...
  21. Replies
    6
    Views
    3,639

    Opinion on line length

    Hey all! This is just a question of style and preference, I guess. But still, I'd like to know how you veterans code. ;)

    Maximum line length in your source code, if any? I read a paper on C...
  22. Replies
    11
    Views
    33,483

    I've also been a bit annoyed by various bugs in...

    I've also been a bit annoyed by various bugs in Dev-Cpp and when I saw you talking about Code::Blocks - an IDE I've never heard of - I decided to give it a go. It's GPL'ed and really neat! I haven't...
  23. Replies
    8
    Views
    1,486

    Thank you, everyone!

    Thank you, everyone!
  24. Replies
    8
    Views
    1,486

    State of string.length()

    Hello! Quick question here, since I haven't gotten any good C++ reference books yet.

    Is the string length calculated each time string.length() is called, or is the value always kept "up-to-date"...
  25. Replies
    7
    Views
    16,790

    Sorry, my -ansi somehow got lost in the mix. :S...

    Sorry, my -ansi somehow got lost in the mix. :S It's supposed to be ANSI C, nothing else. Yes, -std-c99 also solves the problem. :)
Results 1 to 25 of 32
Page 1 of 2 1 2