Bound checking in c/c++

Christos Ricudis ricudis at itc.auth.gr
Thu Jun 17 10:11:48 EEST 2004


On Wed, 16 Jun 2004 19:07:59 +0300
Karaoulis Marios <marios at lemnos.geo.auth.gr> wrote:

> Exo auto to programma
> #include <stdio.h>
> #include <stdlib.h>
> int main()
> {
> float a[5];
> int i;
> a[0]=0; a[1]=1; a[2]=2;
> a[3]=3; a[4]=4; a[15]=5;
> for (i=0;i<=4;i++) printf("%f\n",a[i]);
> printf("%f\n",a[15]);
> return 0;
> } 

Ksereis ti 8a se kanei o costas at lemnos.geo.auth.gr an ypopsiastei oti pas na kaneis kati tetoio se pragmatiko kwdika? Pistepse me, de 8eleis na ma8eis. To exw dei. Den einai wraio 8eama :>. 

> to kano compile os 
> gcc -fbound-checking foo.c
> 
> Alla den gurnaei kapio warning
> otan to trexo gyrnaei apotelesma gia to a[15]
> Ti ginetai?
> Den pianei to flag?

Den mporei na piasei - den eimai sigouros oti yparxei kati poy mporei na se glytwsei eykola apo tetoia la8h sthn C. H Fortran kai h Java einai strong-typed glwsses, kai mporoun na prosexoun kala tous pointers tous (otan exoun :P) kai to memory allocation / garbage collection tous.  

-fbounds-check
         For front-ends that support it, generate additional code
         to check that indices used to access arrays are within
         the declared range.  This is currently only supported by
         the Java and Fortran 77 front-ends, where this option
         defaults to true and false respectively.

Skepsou aplws oti ayto poy egrapses einai h APLH periptwsh. Bound overflow mporei na sou prokypsei se poly pio periplegmenes katastaseis. O monos tropos na to kanei o compiler 8a htan na kanei extend kapoio internal pointer housekeeping structure (nai, apo to myalo mou ta bgazw, den exw dei pote moy ton kwdika tou gcc) me bounds information kai na bazei bounds checking code gyrw apo ta allocations kai ta dereferences, kai pali den eimai apolytws sigouros oti 8a kataferne na ta piasei ola. 

Twra blepw oti to bp project prospa8ei na kanei akribws ayto. Endiaferon. 8a 8ela na ksera se poies periptwseis psofaei :P   

-- 
Christos Ricudis				ricudis at itc.auth.gr
Systems Administrator				+30-2310-998305
IT Support Center
Aristotles University of Thessaloniki, GREECE




More information about the Linux-greek-users mailing list