home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / amiga / programm / 13262 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.9 KB  |  68 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!destroyer!gatech!concert!samba!usenet
  3. From: Todd_Lewis@unc.edu (Todd M. Lewis)
  4. Subject: PropGadgets and Manx C bug
  5. Message-ID: <1992Sep11.151113.9323@samba.oit.unc.edu>
  6. Sender: usenet@samba.oit.unc.edu
  7. Nntp-Posting-Host: guitar.oit.unc.edu
  8. Organization: UNC Office of Information Technology
  9. Date: Fri, 11 Sep 1992 15:11:13 GMT
  10. Lines: 56
  11.  
  12. Below are two very short (6 line) C programs which only differ by
  13. the type of the only variable they contain.  MAXPOT you may
  14. recognize as one of the constants used when manipulating
  15. Intuition slider PropInfo structures.  Below that is the
  16. assembler output produced by Manx C v5.2a.  Note how the one on
  17. the left works, while the one on the right uses register d1 in a
  18. subtraction without ever initializing it.  ARGH!  No wonder I've
  19. been having so much trouble with my slider gadgets.
  20.  
  21. I present this in the hope of saving someone else the time I've
  22. spent trying to get this to work.  The work-around is simple
  23. enough--make the variable "level" unsigned long.  Note that
  24. casting it to unsigned long has no effect on the assembly
  25. instructions produced.
  26.  
  27. /**COMPILES CORRECTLY**/            /**COMPILES INCORRECTLY**/
  28. #define MAXPOT 0xFFFF               #define MAXPOT 0xFFFF
  29. main()                              main()
  30.   {                                   {
  31.     unsigned long level;                unsigned short level;
  32.     level * MAXPOT;                     level * MAXPOT;
  33.   }                                   }
  34.  
  35. Respective outputs from the compiler:
  36.  
  37.   ;:ts=8                            ;:ts=8
  38.   ;#define MAXPOT 0xFFFF            ;#define MAXPOT 0xFFFF
  39.   ;main()                           ;main()
  40.   ;  {                              ;  {
  41.        xdef _main                        xdef    _main
  42.   _main:                            _main:
  43.        link a5,#.2                       link    a5,#.2
  44.        movem.l   .3,-(sp)                movem.l .3,-(sp)
  45.   ;    unsigned long level;         ;    unsigned short level;
  46.   ;    level * MAXPOT;              ;    level * MAXPOT;
  47.        move.l    -4(a5),d0               move.w  -2(a5),d0
  48.        move.l    d0,d1                   swap    d0
  49.        lsl.l     #8,d0                   clr.w   d0
  50.        lsl.l     #8,d0                   swap    d0
  51.        sub.l     d1,d0                   sub.l   d1,d0
  52.   ;  }                              ;  }
  53.   .4                                .4
  54.        movem.l   (sp)+,.3                movem.l (sp)+,.3
  55.        unlk a5                           unlk    a5
  56.        rts                               rts
  57.   .2   equ  -4                      .2   equ     -2
  58.   .3   reg                          .3   reg
  59.   ;                                 ;
  60.   ;                                 ;
  61.        xref .begin                       xref    .begin
  62.        dseg                              dseg
  63.        end                               end
  64.  
  65.  
  66. --
  67. Todd M. Lewis / Todd_Lewis@unc.edu / utoddl@guitar.oit.unc.edu
  68.