Executable semantics in C

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed May 4 07:26:53 PDT 2011


On 04/05/2011 14:45, Robert Jacques wrote:
> On Tue, 03 May 2011 08:20:42 -0400, Bruno Medeiros
> <brunodomedeiros+spam at com.gmail> wrote:
>
>> On 27/04/2011 22:20, Timon Gehr wrote:
>>> Quiz: What does the following code compute?
>>>
>>> import std.stdio;
>>> import core.exception;
>>> void main(){
>>> int a,b;
>>> int[int] aa;
>>> scanf("%d %d",&a,&b);
>>> try{aa[a]=aa[b];printf("Y\n");}catch(RangeError){printf("N\n");}
>>> }
>>
>> What was your point here? Is there even any way an associative array
>> throws a RangeError?
>
> An AA throws a range error if the key is not in the AA during an index
> operation. Since aa is initialized, aa[b] would be expected to throw a
> range error.

Duh me, of course. For a moment I thought that wasn't the case, I ran a 
snippet to test that and no RangeError was thrown. But it turns out what 
I had ran was the old version of the code, not the new one that I 
modified and thought was running.

-- 
Bruno Medeiros - Software Engineer


More information about the Digitalmars-d mailing list