A Conversation for The H2G2 Programmers' Corner

can someone help an absolute beginner in c++?

Post 61

26199

Installing on Linux does take practice... with any luck it will become less frustrating after a while, and simply be annoyingly time-consuming smiley - winkeye


can someone help an absolute beginner in c++?

Post 62

MaW

On Gentoo, most things are a breeze... yes you have to wait for them to compile, but you don't have to sit there watching it all the time.


Minor topic drift

Post 63

Potholer

I was wondering what people's opinions were on the ? operator.

As a side-effect of some recent unexpected work for an interactive testing company, it transpires that ANSI C regards the value of the ? operator as a definite lvalue, whereas C++ (ANSI C++, I think) considers the result to be an lvalue if the two colon-seperated parts have similar type. Apparently, the GNU C compiler follows the C++ model by default, allowing

( a ? a : b ) = c ;
as an equivalent to
if (a) a=c; else b=c;

while ANSI C would barf on the same code.


On an unrelated and vaguely ironically humorous issue, I recently got a book from the local library which was an introduction to network and information security. In the section about the different ways that unauthorised people can access information (social engineering, dumpster diving, etc), I found a piece of paper with the notes which a previous reader had made, and which they had forgotten to remove from the book before returning it to the library. No passwords, unfortunately.


Minor topic drift

Post 64

MaW

Hmm, that makes sense... C++ has a much stricter typing system than C, so that kind of thing is compileable, as the compiler can check if it's okay at compile time, rather than allowing it to crash spectacularly at runtime.


Minor topic drift

Post 65

Potholer

Whoops - just spotted a typo in my post. It should have been that ANSI C considers the value of a whole ? expression as a definite *rvalue*.

I can see some vague utility in allowing
(a ? b : c) = d ;
for reasons of compactness of source code, especially where d is a large expression, but it wouldn't be hard to make an optimising compiler realise that
if (a)
smiley - spacesmiley - spaceb = (some long and complicated expression) ;
else
smiley - spacesmiley - spacec = (same long and complicated expression) ;
could be optimised to be the same as the equivalent conditional expression.

Reading around yesterday, I found that where lvalue-returning conditional expressions are allowed in C/C++ compilers, there is some variation about the meaning of
a ? b : c = d ;
some treat it as
a ? b : (c = d) ;
and some as
(a ? b : c) = d ;

at least the less elegant:
*(a ? &b : &c) = d ;
makes it clearer that something odd is happening, and works consistently across all C and C++ compilers.


Removed

Post 66

Calculator Nerd 256

This post has been removed.


Hidden

Post 67

MaW

Hmm


Hidden

Post 68

Potholer

Hidden posting? I hope I didn't start some kind of Holy War here...


can someone help an absolute beginner in c++?

Post 69

Fazed up

Love the sound affects!!!!


can someone help an absolute beginner in c++?

Post 70

Calculator Nerd 256

no there was no hidden posting. my "friend" aaron waited for me to log on and then overpowered me out of the chair, said some bad stuff, and then REPORTED it. I hope they don't kick me off
smiley - geek>8^B


can someone help an absolute beginner in c++?

Post 71

Calculator Nerd 256

oh and as a response to about a page ago, i am using RH 8
didn't have time to read anything, i was too busy freaking out over the dirty things aaron wrote. i do hope the moderators cover up that stuff at my space
smiley - geek>8^B


can someone help an absolute beginner in c++?

Post 72

Calculator Nerd 256

i never use the ? operator or the switch() function. i am not familiar with the syntax and more comfortable with an ugly line of for()s and if()s
what sound effects?
smiley - geek>8^B


can someone help an absolute beginner in c++?

Post 73

MaW

Technically, switch isn't a function... it's a statement.


can someone help an absolute beginner in c++?

Post 74

Calculator Nerd 256

see? i told u i dun understand switch()
smiley - geek>8^B


can someone help an absolute beginner in c++?

Post 75

Calculator Nerd 256

today is no fun. i just found out i didn't get in to the oklahoma school for science and math
smiley - geek>8^B


can someone help an absolute beginner in c++?

Post 76

MaW

smiley - sadface

I finished my degree smiley - smiley


can someone help an absolute beginner in c++?

Post 77

Calculator Nerd 256

good for you, maybe i can go to college some day. i was really relying on getting into OSSM for high school, though. the one i am in the district for isn't very prestigious if u know what i mean
smiley - geek>8^B


can someone help an absolute beginner in c++?

Post 78

Calculator Nerd 256

i decided that i want to make a 4D RPG.
anyone wanna make me a 4D map?
smiley - geek>8^B


Key: Complain about this post