Welcome, Guest. Please login or register.
July 23, 2025, 08:57:24 AM

Login with username, password and session length

Search:     Advanced search
we're back, baby
*
Home Help Search Login Register
f13.net  |  f13.net General Forums  |  General Discussion  |  Topic: Ignore lists 0 Members and 1 Guest are viewing this topic.
Pages: 1 2 [3] Go Down Print
Author Topic: Ignore lists  (Read 14465 times)
Samwise
Moderator
Posts: 19324

sentient yeast infection


WWW
Reply #70 on: March 27, 2010, 05:59:57 PM

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...   why so serious?
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.   why so serious?
Evil Elvis
Terracotta Army
Posts: 963


Reply #71 on: March 27, 2010, 08:13:47 PM

You can do that in Java/C# too.

Code:
for ( char c = 'A' ; c <= 'Z' ; c++ )
{
        System.out.println((int)c);
//Console.WriteLine((int)c);
}
Morat20
Terracotta Army
Posts: 18529


Reply #72 on: March 27, 2010, 08:23:35 PM

You can do that in Java/C# too.

Code:
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


Reply #73 on: March 27, 2010, 08:27:52 PM

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


WWW
Reply #74 on: March 27, 2010, 08:37:18 PM

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.   Oh ho ho ho. Reallllly?
Quinton
Terracotta Army
Posts: 3332

is saving up his raid points for a fancy board title


Reply #75 on: March 27, 2010, 08:43:45 PM

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


Reply #76 on: March 27, 2010, 09:17:14 PM

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. DRILLING AND WOMANLINESS

Hahahaha!  I'm really good at this!
dusematic
Terracotta Army
Posts: 2250

Diablo 3's Number One Fan


Reply #77 on: March 27, 2010, 10:35:27 PM



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


Reply #78 on: March 28, 2010, 09:34:56 AM

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. DRILLING AND WOMANLINESS

... Ohhhhh, I see.

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


WWW
Reply #79 on: March 28, 2010, 09:50:45 AM

... Ohhhhh, I see.

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.

- And in stranger Iains, even Death may die -

SerialForeigner Photography.
Signe
Terracotta Army
Posts: 18942

Muse.


Reply #80 on: March 28, 2010, 12:33:23 PM

It broke his funny bone!   ACK!

My Sig Image: hath rid itself of this mortal coil.
Morat20
Terracotta Army
Posts: 18529


Reply #81 on: March 28, 2010, 04:47:54 PM

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


WWW
Reply #82 on: March 28, 2010, 07:43:39 PM

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.   Facepalm
bhodi
Moderator
Posts: 6817

No lie.


Reply #83 on: March 28, 2010, 08:02:24 PM

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


Reply #84 on: March 28, 2010, 08:09:32 PM

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


Reply #85 on: March 29, 2010, 01:49:27 PM

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


Reply #86 on: March 29, 2010, 02:10:49 PM

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


Reply #87 on: March 30, 2010, 06:47:27 PM

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


Reply #88 on: April 01, 2010, 06:06:23 PM

Oh my god. Lady Gaga is actually Dr. Mrs. The Monarch!!!!!!

I WILL CUT YOU Shaking fist

If you party with the Party Prince you get two complimentary after-dinner mints
Pages: 1 2 [3] Go Up Print 
f13.net  |  f13.net General Forums  |  General Discussion  |  Topic: Ignore lists  
Jump to:  

Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC