POV-Ray : Newsgroups : povray.off-topic : You lose some... Server Time
7 Sep 2024 03:19:36 EDT (-0400)
  You lose some... (Message 21 to 30 of 31)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 1 Messages >>>
From: andrel
Subject: Re: You lose some...
Date: 5 Oct 2008 09:35:28
Message: <48E8C2ED.3070400@hotmail.com>
On 05-Oct-08 6:42, Chris Cason wrote:
> Slime wrote:
>>>     for (unsigned int i=0; i<c.size(); i++)
>>>       if (c[i]) out.append("1"); else out.append("0");
>> This isn't the cause of your crash, but I recommend not squishing your code 
>> together like that. Keep each statement on a separate line and use brackets 
>> around anything that's not a single simple statement:
>>
>>     for ( unsigned int i = 0; i < c.size(); i++ )
>>     {
>>         if ( c[i] )
>>             out.append( "1" );
>>         else
>>             out.append( "0" );
>>     }
> 
> If he wants brevity he could also code it like this:
> 
>   for (int i = 0; i < c.size(); i++)
>     out.append(c[i] ? "1" : "0");
> 
> which is just as valid and avoids running the if/else together.
> 
Didn't we code that more like out.append("0" + c[i]) just to confuse the 
readers?


Post a reply to this message

From: Fredrik Eriksson
Subject: Re: You lose some...
Date: 5 Oct 2008 09:51:11
Message: <op.uij0rkwh7bxctx@e6600>
On Sun, 05 Oct 2008 15:36:45 +0200, andrel <a_l### [at] hotmailcom>  
wrote:
>>
> Didn't we code that more like out.append("0" + c[i]) just to confuse the  
> readers?

Nitpick: It has to be '0', not "0".


You could also do it like this:
	out += c[i]["01"];

If you were in a particularly foul mood, you could write it like this:
	out += c??(i??)??("01"??);


-- 
FE


Post a reply to this message

From: andrel
Subject: Re: You lose some...
Date: 5 Oct 2008 09:51:41
Message: <48E8C6BB.4040202@hotmail.com>
On 05-Oct-08 15:36, andrel wrote:
> On 05-Oct-08 6:42, Chris Cason wrote:
>> Slime wrote:
>>>>     for (unsigned int i=0; i<c.size(); i++)
>>>>       if (c[i]) out.append("1"); else out.append("0");
>>> This isn't the cause of your crash, but I recommend not squishing 
>>> your code together like that. Keep each statement on a separate line 
>>> and use brackets around anything that's not a single simple statement:
>>>
>>>     for ( unsigned int i = 0; i < c.size(); i++ )
>>>     {
>>>         if ( c[i] )
>>>             out.append( "1" );
>>>         else
>>>             out.append( "0" );
>>>     }
>>
>> If he wants brevity he could also code it like this:
>>
>>   for (int i = 0; i < c.size(); i++)
>>     out.append(c[i] ? "1" : "0");
>>
>> which is just as valid and avoids running the if/else together.
>>
> Didn't we code that more like out.append("0" + c[i]) just to confuse the 
> readers?

Been a long time since I actually did write sufficient amount of C. :( I 
think I meant the character constant '0' and not the string "0".


Post a reply to this message

From: andrel
Subject: Re: You lose some...
Date: 5 Oct 2008 09:54:55
Message: <48E8C77C.9060509@hotmail.com>
On 05-Oct-08 15:51, Fredrik Eriksson wrote:
> On Sun, 05 Oct 2008 15:36:45 +0200, andrel <a_l### [at] hotmailcom> 
> wrote:
>>>
>> Didn't we code that more like out.append("0" + c[i]) just to confuse 
>> the readers?
> 
> Nitpick: It has to be '0', not "0".

Yeah I remembered too late.

> You could also do it like this:
>     out += c[i]["01"];

Is that C or C++?

> If you were in a particularly foul mood, you could write it like this:
>     out += c??(i??)??("01"??);
what += does??(that??)??("Mean"??)


Post a reply to this message

From: Fredrik Eriksson
Subject: Re: You lose some...
Date: 5 Oct 2008 10:03:35
Message: <op.uij1b8k97bxctx@e6600>
On Sun, 05 Oct 2008 15:56:12 +0200, andrel <a_l### [at] hotmailcom>  
wrote:
>
>> You could also do it like this:
>>     out += c[i]["01"];
>
> Is that C or C++?

Either.


>> If you were in a particularly foul mood, you could write it like this:
>>     out += c??(i??)??("01"??);
> what += does??(that??)??("Mean"??)

??( is an alternative token for [. Similarly for ??) and ].


-- 
FE


Post a reply to this message

From: andrel
Subject: Re: You lose some...
Date: 5 Oct 2008 10:38:24
Message: <48E8D1AE.7020501@hotmail.com>
On 05-Oct-08 16:03, Fredrik Eriksson wrote:

> 
>>> If you were in a particularly foul mood, you could write it like this:
>>>     out += c??(i??)??("01"??);
>> what += does??(that??)??("Mean"??)
> 
> ??( is an alternative token for [. Similarly for ??) and ].

I don't remember that one. I seem to have dislocated my k&r and bjarne 
books and I seem not to be able to find that on the web either. Are you 
sure that that isn't just a compiler/hardware specific hack?


Post a reply to this message

From: Warp
Subject: Re: You lose some...
Date: 5 Oct 2008 11:12:44
Message: <48e8d96c@news.povray.org>
andrel <a_l### [at] hotmailcom> wrote:
> > ??( is an alternative token for [. Similarly for ??) and ].

> I don't remember that one. I seem to have dislocated my k&r and bjarne 
> books and I seem not to be able to find that on the web either. Are you 
> sure that that isn't just a compiler/hardware specific hack?

http://en.wikipedia.org/wiki/C_trigraph

-- 
                                                          - Warp


Post a reply to this message

From: Fredrik Eriksson
Subject: Re: You lose some...
Date: 5 Oct 2008 11:18:35
Message: <op.uij4s9vt7bxctx@e6600>
On Sun, 05 Oct 2008 16:39:42 +0200, andrel <a_l### [at] hotmailcom>  
wrote:
>>  ??( is an alternative token for [. Similarly for ??) and ].
>
> I don't remember that one. I seem to have dislocated my k&r and bjarne  
> books and I seem not to be able to find that on the web either. Are you  
> sure that that isn't just a compiler/hardware specific hack?

Yes, I am sure. They are called trigraphs and are listed in section 2.3 of  
the C++ standard.

Strictly speaking, they are not actually alternative tokens. They are  
substituted before any other processing of the source.

There is a set of actual alternative tokens though. They are sometimes  
called digraphs. You could thus write:
	out += c<:i:><:"01":>;


-- 
FE


Post a reply to this message

From: andrel
Subject: Re: You lose some...
Date: 5 Oct 2008 11:46:46
Message: <48E8E1B4.3050004@hotmail.com>
On 05-Oct-08 17:12, Warp wrote:
> andrel <a_l### [at] hotmailcom> wrote:
>>> ??( is an alternative token for [. Similarly for ??) and ].
> 
>> I don't remember that one. I seem to have dislocated my k&r and bjarne 
>> books and I seem not to be able to find that on the web either. Are you 
>> sure that that isn't just a compiler/hardware specific hack?
> 
> http://en.wikipedia.org/wiki/C_trigraph
> 
Thanks warp and frederick. This wiki page still keeps me wondering when 
these trigraphs were introduced. Must be before the 1994 digraphs (which 
is indeed long after my sort of formal training in C).

I could not find them with google. searching for ??) did not give any 
result. Any of the google wizards know what I should have asked? (Apart 
from trigraph, because that was the term I didn't know, otherwise I 
would not be looking)


Post a reply to this message

From: Fredrik Eriksson
Subject: Re: You lose some...
Date: 5 Oct 2008 12:22:55
Message: <op.uij7sgtx7bxctx@e6600>
On Sun, 05 Oct 2008 17:48:04 +0200, andrel <a_l### [at] hotmailcom>  
wrote:
>>
> This wiki page still keeps me wondering when these trigraphs were  
> introduced. Must be before the 1994 digraphs (which is indeed long after  
> my sort of formal training in C).

Late eighties I think.


-- 
FE


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 1 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.