Pages: 1 2 [3]
|
 |
|
Author
|
Topic: Ignore lists (Read 14465 times)
|
Samwise
Moderator
Posts: 19324
sentient yeast infection
|
Seems like that should "work" perfectly well; the assignment in the for loop overrides the '1' assignment, and I don't think C will complain too much if you assign an int to a char. Now, if he'd been trying to count to 500 in that loop instead of 5...  It was so long ago I have no idea what language it was. Only that he was treating a character like an int, and couldn't grasp that while the character might be a number, it wasn't an INTEGER and no, the computer didn't "know" it was a number. In C/C++ you can actually do that just fine; a char is just a one-byte number, and '1' is just an alias for the number 49 (ASCII). You can even do something like: for ( char c = 'A' ; c <= 'Z' ; c++ ) { printf( "%c", c ); } Java would probably pitch a fit about it, though, and a Java weenie would probably pitch a bigger one. 
|
|
|
|
Evil Elvis
Terracotta Army
Posts: 963
|
You can do that in Java/C# too. for ( char c = 'A' ; c <= 'Z' ; c++ ) { System.out.println((int)c); //Console.WriteLine((int)c); }
|
|
|
|
Morat20
Terracotta Army
Posts: 18529
|
You can do that in Java/C# too. for ( char c = 'A' ; c <= 'Z' ; c++ ) { System.out.println((int)c); //Console.WriteLine((int)c); }
Yeah, I know you can loop a character through the ASCII codes, but he was treating it entirely like an int. C++ overloads enough functions to get away with that, but either raw C or Pascal doesn't.
|
|
|
|
Quinton
Terracotta Army
Posts: 3332
is saving up his raid points for a fancy board title
|
char is novel in Java for being the *only* unsigned primitive data type in the language (also for being 16 bits wide, which may be a surprise for some folks).
One of my many small gripes about the language is the required cast when assigning to byte or char from int.
Regarding char in C, you most certainly can *always* treat it like an int, it always promotes to the larger type in expressions and larger types may be freely assigned to variables of type char. The only gotcha is that it has a range of -128 to 127 (or 0 to 255 in some compilers, but less common these days).
|
|
|
|
Samwise
Moderator
Posts: 19324
sentient yeast infection
|
The only gotcha is that it has a range of -128 to 127 (or 0 to 255 in some compilers, but less common these days).
If it's important, of course, you'd just declare the signedness to remove all doubt. 
|
|
|
|
Quinton
Terracotta Army
Posts: 3332
is saving up his raid points for a fancy board title
|
Yup. Something I look for when interviewing people. Actually, now that I think about it, it'd be fun to work up a plausible situation where you should explicitly declare something signed char -- this is a bit more insidious, since the bulk of the time char is signed by default (need to check, might be per ANSI these days), but in some cases it can be unsigned. As it is, candidates regularly fail to use an unsigned char when they need to.
gcc extensions make everything weird, too. By strict language spec pointer math on void* is undefined and illegal, but the linux kernel, for example, relies on gcc treating it as valid and equivalent to char* for that purpose, which does avoid a lot of clunky casting things to char* to do address manipulation.
|
|
|
|
Lantyssa
Terracotta Army
Posts: 20848
|
I think trying to screen out people on a message board makes you an even bigger pussy though.
Sorry, I can't read you over the sound of how ignored you are. 
|
Hahahaha! I'm really good at this!
|
|
|
dusematic
Terracotta Army
Posts: 2250
Diablo 3's Number One Fan
|
Edit: Trying to be more of a chill guy now. Trying
|
|
« Last Edit: March 27, 2010, 10:37:16 PM by dusematic »
|
|
|
|
|
Hoax
Terracotta Army
Posts: 8110
l33t kiddie
|
I think trying to screen out people on a message board makes you an even bigger pussy though.
Sorry, I can't read you over the sound of how ignored you are.  ...  Not impressed or amused. You better put me on ignore if people are going to start posting shit like this, posters in glass houses should shut the fuck up about ignoring others.
|
A nation consists of its laws. A nation does not consist of its situation at a given time. If an individual's morals are situational, then that individual is without morals. If a nation's laws are situational, that nation has no laws, and soon isn't a nation. -William Gibson
|
|
|
IainC
Developers
Posts: 6538
Wargaming.net
|
...  Not impressed or amused. You better put me on ignore if people are going to start posting shit like this, posters in glass houses should shut the fuck up about ignoring others. Show us on the doll where the politics thread touched you.
|
|
|
|
Signe
Terracotta Army
Posts: 18942
Muse.
|
It broke his funny bone! 
|
My Sig Image: hath rid itself of this mortal coil.
|
|
|
Morat20
Terracotta Army
Posts: 18529
|
Yup. Something I look for when interviewing people.
When I interviewed for my current job, maybe 7 years ago? The manager for the section (ie: the guy what made the call) told me he was explicitly barred from quizzing me to determine my coding abilities, and had to rely on my resume, education, and references per HR guidelines. He then noted that the best way to interview someone, once you got past the basics, was yank up a piece of code that had 'caused some problems' and talk shop. His 'piece of code' was a lovely collection of "Fucking hell!" bugs and obscure algorithms and techniques, with just enough comments and context for someone with a decent level of skill to explain what was going on and what went wrong. To my everlasting shame (and I still blame it on the fact that I was four years out of doing raw C and had, in fact, been doing OO-stuff since) I did miss a function pointer, but once he pointed it out I was able to explain what the code was doing and why it wasn't working. (Specifically, a rather tricky little scope problem).
|
|
|
|
Samwise
Moderator
Posts: 19324
sentient yeast infection
|
I used to show people who claimed C++ proficiency something like this: int* five() // this function should return a pointer to the number 5 { int x = 2 + 3; return &x; } and ask what was wrong with it. Most of them failed. 
|
|
|
|
bhodi
Moderator
Posts: 6817
No lie.
|
Haven't done C++ for over a decade, but uh... scope? Doesn't that value go away once that function does, since it was declared within? Is the real way to do it is to pass a pointer that you want the value set of?
I limit myself to non-pointer and autotypedef'd languages.
|
|
« Last Edit: March 28, 2010, 08:09:57 PM by bhodi »
|
|
|
|
|
Morat20
Terracotta Army
Posts: 18529
|
Scope. The address holding int gets freed the moment the function is returned. It's actually a fairly common pointer mistake, or at least, it's one of the first things I look for when my program is crapping itself.
|
|
|
|
Lantyssa
Terracotta Army
Posts: 20848
|
Not impressed or amused. You better put me on ignore if people are going to start posting shit like this, posters in glass houses should shut the fuck up about ignoring others.
Was that part for me or slog? I've got a great rant going, but realized you might have gotten my humor and were poking him, in which case it was mean spirited.
|
|
« Last Edit: March 29, 2010, 01:51:43 PM by Lantyssa »
|
|
Hahahaha! I'm really good at this!
|
|
|
Tarami
Terracotta Army
Posts: 1980
|
This thread has gone places! Remember, whenever you need a can of worms opened, count on me.
|
- I'm giving you this one for free. - Nothing's free in the waterworld.
|
|
|
TheWalrus
Terracotta Army
Posts: 4321
|
I'm pretty sure Hoax completely missed your point Lan. I'm not a betting man, and I'd bet on it
|
vanilla folders - MediumHigh
|
|
|
Mattemeo
Terracotta Army
Posts: 1128
|
Oh my god. Lady Gaga is actually Dr. Mrs. The Monarch!!!!!!
I WILL CUT YOU 
|
If you party with the Party Prince you get two complimentary after-dinner mints
|
|
|
|
Pages: 1 2 [3]
|
|
|
 |