home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 644 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  8.0 KB

  1. Path: nntp.teleport.com!sschaem
  2. From: sschaem@teleport.com (Stephan Schaem)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: PPC compilers
  5. Date: 9 Jan 1996 23:08:33 GMT
  6. Organization: Teleport - Portland's Public Access (503) 220-1016
  7. Message-ID: <4cushh$dmn@maureen.teleport.com>
  8. References: <john.hendrikx.40ka@grafix.xs4all.nl> <4b77tq$htp@serpens.rhein.de> <MQAQx*XOe@yaps.rhein.de> <4bqhnf$6g5@sunsystem5.informatik.tu-muenchen.de> <jasonb.820051107@cs.uwa.edu.au> <4c9i2l$h3i@sunsystem5.informatik.tu-muenchen.de> <4cf0ep$233@ra.i
  9.    <4ck47h$g07@maureen.teleport.com> <jasonb.820919731@cs.uwa.edu.au> <4com6v$415@maureen.teleport.com> <jasonb.821098303@cs.uwa.edu.au> <4crfb9$djs@maureen.teleport.com> <jasonb.821175824@cs.uwa.edu.au>
  10. NNTP-Posting-Host: kelly.teleport.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Jason S Birch (jasonb@cs.uwa.edu.au) wrote:
  14. : sschaem@teleport.com (Stephan Schaem) writes:
  15. : >Jason S Birch (jasonb@cs.uwa.edu.au) wrote:
  16. : >: Again: *If* he's trying to create a data type with certain
  17. : >: implementation-dependent size-requirements (such as in the bltcon0
  18. : >: case, assuming no headers to give us one) *then*, at that point in
  19. : >: time, he has to know the size of the type in order to define it
  20. : >: correctly. He stated that earlier - check what I've underlined.
  21.  
  22. : > He said he would create a structure... not a new type.
  23.  
  24. : You're saying a new structure *isn't* a new type?
  25.  
  26.  I'm saying decalring element of a structure... if you make an element
  27.  public & declar it a ulong... you better keep it a ulong from then on.
  28.  
  29. : > Now, tell me how he can forget that chipregs->bltcon0 is
  30. : > of type UWORD when he will declar *b and use *b (I guess you
  31. : > could forget what type are your variable, but personaly think its
  32. : > not to wise) 
  33.  
  34. : typedef uword bltcon0_t;
  35. : ...
  36. : struct chipregs_t {
  37. :     ...
  38. :     bltcon0_t    bltcon0;
  39. :     ...
  40. : };
  41.  
  42. : struct chipregs_t    chipregs;
  43. : bltcon0_t            *b;
  44.  
  45. : Now he can safely use *b wherever a bltcon0_t is required, and given
  46. : sufficient support functions, never needs to know that it's a uword -
  47. : all he has to keep in mind are what values a bltcon0_t is allowed to
  48. : take.
  49.  
  50.  Ok, I agree, with support function this take a all new dimention.
  51.  
  52. : > I'm sorry again , I dont see how you can program not knowing  
  53. : > the type of your variable when you use them? Is it a pointer to a
  54. : > string C string? a pointer to a P String? 
  55.  
  56. : Again, you're misunderstanding. If you have a type blah, and a
  57. : function takes a variable of type blah *, then by all means create a
  58. : variable of type blah (or blah *) and pass it's address (or the
  59. : variable itself) to the function. You do *not*, however, need to know
  60. : if blah is really, say, a 32-bit integer. With assembler, you do.
  61.  
  62.  In assembler you need to know its of type long... long just
  63.  happen to be a 32bit integer. you will declare you variable in asm
  64.  of type long, and use it has a long... in C you will declare of
  65.  the variable of type blah and use it has type blah.
  66.  
  67.  Now you foget your variable if of type blah and you will probably write
  68.  something the compiler will chock on convert for you, if possible.
  69.  
  70.  In asm you forget your variable is of type word and you use it to 
  71.  store a long result... you are dead, I never said assembler to type
  72.  chacking. I just said in asm or C you need to know your variable type.
  73.  
  74. : > Should I mask the variable
  75. : > before I shift? etc...
  76.  
  77. : If you use bitfields, you don't even have to care about masking and
  78. : shifting:
  79.  
  80. : typedef struct {
  81. :   int foo : 2;
  82. :   int bar : 4;
  83. :   int bob : 10;
  84. : } fred_t;
  85.  
  86.  For me here I see a structure with 3 type.
  87.  
  88.  foo, bar, bob need to be defined somehow to the programmer. 
  89.  
  90.  is bob an integer value holding a range of 0 to 1024 for luminance
  91.  is foo really a bolean value and range from true to false?
  92.  ....
  93.  
  94.  But what I said with bit masking is that for example >> replace the
  95.  incoming bit with zero but you cant assume what those are. 
  96.  
  97. : Structures *are* types. 
  98.  
  99.  element of structure are not, unless you can
  100.  
  101.  structure.element  variable;
  102.  
  103. : > move.type    (a0),(a1) ... so what if type read .word or .chipreg
  104.  
  105. : The "so what" is that you *need* to know if it really is a type .word,
  106. : or .byte, and can't simply use it as type .chipreg. Oh, and you have
  107. : to repeatedly say .word (or whatever) almost every time you use it.
  108.  
  109.  In C or ASM I know my variable type... In asm I write it down, in C
  110.  I dont. The point is I know my variable type, that mean I know the type
  111.  range. (bolean, short integer, long integer, real, etc..)
  112.  
  113.  If you write
  114.  
  115.  vector    a,b,c;
  116.  
  117.  ...
  118.  
  119.  c = a*b;
  120.  
  121.  etc..
  122.  
  123.  without knowing that vector is actually a strcture you are just unwise.
  124.  You HAVE TOO in C or asm know what are your variable type, and know what
  125.  the type is.
  126.  
  127. : > In asm you are forced to write what your thinking in all its detail,
  128. : > this mean forced to know your variable type. Something you should do
  129. : > even in C.
  130.  
  131. : Not if you want portable code, you shouldn't, and with sufficient
  132. : support functions, you needn't.
  133.  
  134.  Soon we will talk about c++ vs asm... support function where never in the
  135.  picture till now. but what I'm saying is, you dont forget your variable
  136.  type after you declar them, its just not possible... and if you
  137.  really do not know the type definition you will not use them directly,
  138.  but use function
  139.  
  140.  In asm the chip offer basic function on type like  WORD  and LONG, but
  141.  you are limited to those only at the chip level. Speaking of 
  142.  portable code in asm is silly, but if you want to write high level code
  143.  you will create typed objects & taged functions + marcos... 
  144.  
  145.  The thing I agree is that you cannot typdef a type in asm (Its possible
  146.  just not ofered).
  147.  
  148. : >: The question is not about whether you need to know if a variable is a
  149. : >: float or a long, since they are "abstract" types (and can be different
  150. : >: sizes on different machines). The question is whether you need to know
  151. : >: how many bits are in each, and what each bit means. In assembler, you
  152. : >: do need to know the former, and occasionally the latter.
  153.  
  154. : > When you program in C... on what basis do you select your variable type?
  155. : > Do you limit yourself to int/float? for all integer work you use int, 
  156. : > and real you use float?
  157.  
  158. : Of course not. If I need a lot of precision, I use double. If I prefer
  159. : speed and it doesn't need to be so accurate, I use float. If it
  160. : doesn't need to be floating point at all, I'll use an ordinal type. If
  161. : I don't want to have to care how big it's going to be on a particular
  162. : implementation, I'll go with long or perhaps "natural", where natural
  163. : can be typedef'd appropriately when sizeof(word) and sizeof(long) are
  164. : known. You are quite welcome, as I've said, to use the knowledge that
  165. : ANSI guarantees. If you want to be safe, however, you should not use
  166. : information that your particular implementation defines.
  167.  
  168. : > In C or asm I choose type according the the min range they hold.
  169. : > I cant imagine choosing a type for my operation without knowing the
  170. : > type range.
  171.  
  172. : You can't know the type range beforehand for any possible
  173. : implementation. C does not guarantee it. You can use sizeof at compile
  174. : time, however.
  175.  
  176. : >: > ANSI define very well the minimum size of its type.
  177.  
  178. : >: It does *not* define that ushort is the same as two bytes, which is
  179. : >: what you are claiming above as being equivalent. It only guarantees
  180. : >: that char <= short <= long.
  181.  
  182. : > It define that ushort can hold value from 0 to 65535... this is what I
  183. : > claim. ANSI C do define min range for the basic types, it would be
  184. : > unthinkable otherwise.
  185.  
  186. : It does *not* define that ushort can hold values from 0 to 65535.
  187. : Check it. There are machines with other than multiples of 8 bit word
  188. : sizes, you know.
  189.  
  190. : > Stephan
  191.  
  192. : -- 
  193. : Jason S Birch                        ,-_|\ email: jasonb@cs.uwa.edu.au
  194. : Department of Computer Science      /     \ Tel (work): +61 9 380 1840
  195. : The University of Western Australia *_.-._/ Fax (work): +61 9 380 1089
  196. : Nedlands  W. Australia  6907             v  Tel (home): +61 9 386 8630
  197.  
  198. --
  199. sschaem@teleport.COM  Public Access User -- Not affiliated with Teleport
  200. Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81)
  201.