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,315 of 2,978   
   Dr Engelbert Buxbaum to RadSurfer   
   Re: TPascal Alot Like QBasic   
   05 Feb 05 18:43:41   
   
   From: engelbert_buxbaum@hotmail.com   
      
   RadSurfer wrote:   
      
   > OK! TP 5.5 appears to be somewhat like Qbasic and VBforDos...   
      
   Did you put on your asbestos suit before posting this?   
      
   >   
   > What am I misisng here:   
   >   
   > if ( a and b ) then { do something }       { Error: Boolean Expected! }   
      
   That depends on the type of a and b. If both are boolean, above   
   expression will work. If however a and b are, for example, byte   
   variables, AND will perform a bitwise logical AND operation, resulting   
   in another variable of type byte. Then the complaint of the compiler is   
   absolutely correct.   
      
   > if ((a and b) <> 0) then { do something }  { AOK, allowed, Boolean   
   > result }   
   >   
   > Sheesh! I know of no other language that has this distinction.   
   > What am I missing here?   
      
   The fact that Pascal (and its sucessors Modula and Oberon) are strongly   
   typed languges, where explicit type conversions are required. C for   
   example treats the number "0" equal to the boolean "false" and a number   
   larger than 0 as boolean "true". That sort of thing makes code hard to   
   read and maintain, and is a frequent source of hard to trace errors (the   
   so called "software crisis", accumulation of programms with errors that   
   no one can repair, is the result of the use of such languages). In   
   Wirth-languages the compiler will complain if you mix types like that,   
   unless you do a proper type conversion. Note that the conversion does   
   not result in maschine instructions, it is merely a way of telling the   
   compiler: "Yes, I know that these variables have different types, but   
   just this once I want them treated equal, so don't shout at me".   
      
   >   
   > Also, like QB and VBfDos, I notice that apparently no attempt to   
   > distinquish   
   > between signed and unsigned is done; and yes usually there are various   
   > work-arounds; but its a pain to have to convert.   
      
   Of course such a distinction is made: byte vs shortint and word vs   
   integer.   
      
   >   
   > to use GetMem, I 1st declare a "pointer" (whatever that really means),   
   >   
   > BlockPtr: pointer;   
   >   
   > getmem(BlockPtr, AmountRam);   
   >   
   > What exactly is this "pointer" ? A   far*  that is 24-some-bits, or   
   > what?   
      
   A pointer is, loosely speaking, an address in the computers memory.   
   Under this address data, referenced as pointer^, are stored. Hence the   
   number of bits in a pointer depends on the hardware.   
      
   GetMem(VariablePointer, SizeOf(Variable) simply reserves the amount of   
   memory required to store Variable, stores the Variable in that space and   
   puts the start-address into VariablePointer.   
      
   Note that with pointers the programmer, not the compiler, is responsible   
   for respecting the bounds of reserved memory. If you reserve space for a   
   byte variable (8 bit) nothing prevents you from writing a word variable   
   (16) bit into it, the excess 8 bit will overwrite whatever comes after   
   the byte variable in memory, for example the code of some program.   
   Buffer overflow errors (exploited by some computer worms) are based on   
   such a mechanism.   
      
   > If is possible to convert/treat this "pointer" as a purely integer   
   > value ?   
      
   Yes, but of course that requires type conversion. Note however that in a   
   well-structured language like Pascal pointer-arithmetic is rarely if   
   ever required (unlike C, for example).   
      
   > Is type-casting ever done in TPascal ?   
      
   Yes.   
      
      
   You should probably get a book on Pascal from your local library and try   
   to learn proper structured programming, as opposed to hacking. Pascal   
   and its successor provide the means of doing that. Once you have learned   
   that discipline, you will be able to use less strict languages like C or   
   Basic with much more efficiency.   
      
   --- 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