Executable semantics in C

Robert Jacques sandford at jhu.edu
Wed May 4 06:45:54 PDT 2011


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.


More information about the Digitalmars-d mailing list