![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Sun, 05 Oct 2008 15:36:45 +0200, andrel <a_l### [at] hotmail com>
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 05-Oct-08 15:51, Fredrik Eriksson wrote:
> On Sun, 05 Oct 2008 15:36:45 +0200, andrel <a_l### [at] hotmail com>
> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Sun, 05 Oct 2008 15:56:12 +0200, andrel <a_l### [at] hotmail com>
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
andrel <a_l### [at] hotmail com> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Sun, 05 Oct 2008 16:39:42 +0200, andrel <a_l### [at] hotmail com>
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On 05-Oct-08 17:12, Warp wrote:
> andrel <a_l### [at] hotmail com> 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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
On Sun, 05 Oct 2008 17:48:04 +0200, andrel <a_l### [at] hotmail com>
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
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Orchid XP v8 nous illumina en ce 2008-10-04 14:37 -->
> Hmm, and I though everything was going so well. :-/
>
> OK, any C++ experts have any idea why this code snippet causes my
> program to crash at runtime?
>
> typedef std::vector<bool> Codeword;
>
> std::string codeword(const Codeword &c)
> {
> std::string out;
>
> for (unsigned int i=0; i<c.size(); i++)
> if (c[i]) out.append("1"); else out.append("0");
>
> return out;
> }
>
> "Unhandled exception at 0x00414166 in Huffman01.exe: 0xC0000005: Access
> violation reading location 0x00000004."
>
> The code looks fine to me - but what I do know?
>
Maybe you have an uninitialised pointer.
Do you get any output? If you don't, it mean that the variable "c" don't get
initialised properly.
Look at the caller. Maybe the variable that is supposed to be passed is in fact
a null, or an uninitialised pointer, or maybe a constant.
--
Alain
-------------------------------------------------
"The way England treats her prisoners, she doesn't deserve to have any."
--Oscar Wilde
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |