Eight, Nine, Ten...

Started by
31 comments, last by Khatharr 11 years, 1 month ago

#define FOURTY_TWO (042)

That's even worse!!!

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Advertisement

That's even worse!!!

This used to happen to me when I was trying to align constants properly. Nowadays I just put spaces instead, been burned too often by this damn octal notation "feature" which I'm guessing nobody actually uses, except the odd raw socket hacker (if even). Permission bits are another one, but constants for those are already defined anyway.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


That's even worse!!!

This used to happen to me when I was trying to align constants properly. Nowadays I just put spaces instead, been burned too often by this damn octal notation "feature" which I'm guessing nobody actually uses, except the odd raw socket hacker (if even). Permission bits are another one, but constants for those are already defined anyway.


at one point I made things more orthogonal (for my script language) by adding several number notations:
0b... //binary
0c... //octal
0d... //decimal
in addition to:
0x... //hexadecimal

then got into a big mental debate as to whether or not to keep '0' by itself as an octal prefix, make it decimal, or maybe just deprecate it and issue a warning...

note, '_' is also a spacer, so:
0d999_999_999
is the same as:
999999999

likewise:
0x5CD13A42_3B9AC9FFL
or:
999_999_999_999_999_999L
or:
0x0DE0_B6B3__A763_FFFFL

Octal was big back in the day when C was being made, maybe even moreso than hexadecimal. These days nobody really uses it since it can't be aligned nicely to 8-bit (some computers back then had words with a bit count multiple of 3, so octal probably made a lot more of sense).

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

But they could have made it useful by adding pluses!


#define ONE     +1
#define TWENTY  +20
#define HUNDRED +100
 
// Here's a little example
#include <iostream>
 
int main()
{
    int x = ONE;
    std::cout << x << std::endl;
 
    x = ONE HUNDRED;
    std::cout << x << std::endl;
 
    x = ONE HUNDRED TWENTY;
    std::cout << x << std::endl;
 
    x = ONE HUNDRED TWENTY ONE;
    std::cout << x << std::endl;
}

Or even worse:


 
#define ONE     +0x001
#define TWENTY  +0x020
#define HUNDRED +0x100
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

....snip...

just...just....o god my eyes....

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Still trying to figure out the reasoning behind that. Is that what happens when your code analysis tool complains about "magic numbers" and somebody just decides to "fix it"?

Because having one such tool complain about '0' being a "magic number" really made me question the worth of that tool and what the creators' code would look like.

f@dzhttp://festini.device-zero.de

But they could have made it useful by adding pluses!


#define ONE     +1
#define TWENTY  +20
#define HUNDRED +100
 
// Here's a little example
#include <iostream>
 
int main()
{
    int x = ONE;
    std::cout << x << std::endl;
 
    x = ONE HUNDRED;
    std::cout << x << std::endl;
 
    x = ONE HUNDRED TWENTY;
    std::cout << x << std::endl;
 
    x = ONE HUNDRED TWENTY ONE;
    std::cout << x << std::endl;
}

Or even worse:


 
#define ONE     +0x001
#define TWENTY  +0x020
#define HUNDRED +0x100

Sadly this doesn't fully work:


TWO HUNDRED == 102

But don't worry - we can fix it! We just need to be "clever"...


#define AND +0
#define ONE +1
#define TWO +2
#define TWENTY +20
#define HUNDRED *100
 
// Here's a little example
#include <iostream>
 
int main()
{
    int x = TWO HUNDRED AND TWENTY ONE;
    std::cout << x << std::endl;
    // prints 221
}

This way you even get to write grammatically correct numbers. happy.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

I think we should pool our efforts and make a programming language where this kind of thing is sane.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I think we should pool our efforts and make a programming language where this kind of thing is sane.

http://thedailywtf.com/Articles/The_Secret_to_Better_C.aspx

This topic is closed to new replies.

Advertisement