home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,090 of 2,978   
   Wolf Behrenhoff to Ruud Baltissen   
   Re: Problem with array[....] of char   
   08 Nov 04 16:34:56   
   
   From: NoSpamPleaseButThisIsValid2@gmx.net   
      
   Ruud Baltissen wrote:   
   > program OK;   
   >   
   > const   
   >   tcac1 : array[0..5] of char = '012345';   
   >   tcac2 : array[0..5] of char = ('9', '8', '7', '6', '5', '4');   
   >   
   > begin   
   >   writeln(tcac1);   
   >   writeln(tcac2);   
   > end.   
   >   
   > I expected:   
   > 012345   
   > 987654   
   >   
   > but got:   
   > 012345987654   
   > 987654   
      
   Null terminated strings.   
      
   > It was clear to me that writeline didn't treat tcac1 as a string otherwise it   
   > wouldn't show '0' IMHO. The next idea was that it was treated as a   
   zero-string.   
   > So I placed "by : byte = 0;" between tcac1 and tcac2. Hurray, it worked!   
   Then I   
   > changed '0' into '85' and expected to see   
   >   
   > 012345U987654   
   > 987654   
   >   
   > but I got:   
   >   
   > 012345U   
   > 987654   
   >   
   > Who can explain this behaviour?   
      
   That is because of word-alignment. The compiler places the variables at   
   even positions in memory and thus adds a #0 automatically. To see that,   
   do the same with tcac1: array[0..6] (odd size). Then try it with {$A-}   
   and {$A+} to see the difference.   
      
   Wolf   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca