7
7Raiden
7y

How much I hate when I see

double x;
if (x = 1)
do_something();

Seriously, why is that so appealing to you?

As well as

int i = 0;
for (; i < n; ++i)
do_something();

Comments
  • 0
    Sorry, but 'initialize'
  • 2
    @Mitiko american english / british english
  • 3
    @Mitiko yup, if you are American and/or speak American English. I'm Italian and I like it more the British way!
  • 0
    Oops, sorry. Not a native speaker, too
  • 1
    int i = 0;

    for(; i<5; i++)
    {
    k = my_array[i];
    if(k % 5 == 0) break;
    }

    t = my_array[i].val;

    ...

    Maybe you need it, maybe you must comply to C89 specs...
  • 0
    Ok...
    I just have to..

    double x;
    if(x == 1) not if(x = 1) - that is assignment :P

    And if you have a double, please don't compare, use diff to a specific precision.
  • 0
    Is it not possible to block scope a variable to the loop in c???
  • 0
    @-eth True that, and I don't see nothing bad with it. Also, what if you create an additional variable with a *meaningful* name (such as the one that indicates why you broke the loop)?
  • 0
    @viking8 there's no typo in my post. I meant the assignment (otherwise where would the rant be ;) ).

    Also, sometimes you need special case handling, like if something is not as expected you make x = -1. In other case of course you should include a tolerance!
  • 0
    Yessss. This is damn irritating.
  • 1
    @nicholai it wasn't until C89 I think. You actually *had* to declare every variable on the very top of your function
  • 1
  • 0
    @nicholai ikr

    And before ANSI C, function definitions looked like this:

    main(argc, argv) // 'int' assumed as return type and as type for 'argc'
    char** argv;
    {
    // code
    }
Add Comment