[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Kode der aldrig bliver kxrt?



On Thu, 17 Aug 2000, Bjarke Bruun wrote:

> Karl Pálsson wrote:
> > 
> > Ja, det er en bug.
> 
> Nej det er ikke en bug - et int array på [2] er 0,1 og 2 - da plads [2]
> ikke behøver at være NULL (læs '\0') da '\0' er NULL = 0, derfor er det
> ikke en bug.
> 
> Dette lille program beviser det:
> 
> #include <iostream> 
> void main() 
> { 
>   int sum[2]; 
>   for (int x=0;x<3;x++) 
>     sum[x]=x; 
>   for (int x=0;x<3;x++) 
>     cout << x << endl;
> }

Det er heldigvis noget vrøvl - ellers var jeg da også blevet dybt rystet.

Check dette program:

#include <iostream> 
int main() 
{ 
  int sum[2]; int ged; 
  ged = 0;
  for (int x=0;x<3;x++) 
    sum[x]=x; 
  for (int x=0;x<3;x++) 
    cout << "sum[x] : " << sum[x] << endl;
  cout << "ged : " << ged << endl;
  return 0;
}

Stort set dit, bortset fra at jeg har nogen navne på print, og den ekstra
variabel "ged".

Her er programmet, når man kører det med gcc på en linux maskine:

nanna > uname && g++ -o tmp -Wall tmp.cc && ./tmp
Linux
ged : 0
sum[0] : 0
sum[1] : 1
sum[2] : 2
ged : 0

Alt er tilsyneladende fint fint.

Her er det samme program, oversat med gcc på en hpux maskine og kørt der:

hermod > uname && g++ -Wall -o tmp.hpux tmp.cc && ./tmp.hpux
HP-UX
ged : 0
sum[0] : 0
sum[1] : 1
sum[2] : 2
ged : 2

Det demonstrerer ret tydeligt at sum[2] og ged er det samme, eller rettere
at når gcc kompileren ikke forsøger at lægge variablene ud så de passer
til cache linie, eller hvad det nu er den foretager sig, så får man fejl -
som i tilfældet med HPUX.

Pyha, troede lige min verden var fuldkommen rystet, men bare et eksempel
på den slags fejl der opstår hvis man tager oversætteren på een platform
for gode varer.

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
The Microsoft Dictionary

     security: Asks for a password. Example: Windows 95 has a high 
               level of security because it asks for a password.



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *