home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d03xx / d0353.lha / NorthC / NorthC2.LZH / bin / Bugs.doc < prev    next >
Text File  |  1990-05-01  |  9KB  |  348 lines

  1.  
  2.   (c) 1990 S.Hawtin.
  3.   Permission is granted to copy this file and NorthC provided that:
  4.    1) Neither are used for commercial gain
  5.    2) This notice is included in all copies
  6.    3) Altered copies are marked as such
  7.    4) Each copy of NorthC is accompanied by a copy of this file.
  8.  
  9.   No liability is accepted for the contents of the file or the NorthC program.
  10.  
  11.   Bugs.doc      within        NorthC
  12.  
  13.  
  14.   This file gives some hints about problems with "NorthC" programs, if 
  15. you find that a program you have compiled is behaving in a way you really
  16. cannot explain and "libc.doc" is no help, you should read this file.
  17.  
  18.   This file is split into three sections, first the list of known bugs in 
  19. the current release, next a list of bugs fixed by this and previous releases 
  20. and finally a list of "hints".
  21.  
  22.   The known bugs are listed under the release that they were first noticed
  23. in, the fixes are listed under the release that they were implemented in.
  24.  
  25.   The "hints" cover everything from bugs I have no immediate intention of 
  26. fixing to problems with the 'C' language that have caught me out in the 
  27. past.
  28.  
  29.  
  30. Bugs
  31. ****
  32.  
  33. Version 1.1
  34. ***********
  35.  
  36. 1.1.1  Standard C
  37.  
  38.   There are a number of features of ANSI 'C' that are not implemented in 
  39. NorthC.  NorthC is a fairly standard Kernigan & Ritchie first edition 'C' 
  40. that has been extended to move towards ANSI.
  41.  
  42.   The features that I know are missing are
  43.  
  44.     a)  locales
  45.     b)  structure returns
  46.     c)  function prototypes
  47.     d)  #pragma #elif #val #error
  48.     e)  The '#' and '##' operators
  49.     f)  concatenating adjacent strings
  50.     g)  multibyte characters
  51.     h)  floats & doubles are too small
  52.     i)  volatile and const storage classes
  53.  
  54.  
  55. 1.1.2  Assignments in if statements
  56.  
  57.   The assignment operator can be incorrectly optimised away in some 
  58. situations, for example the code
  59.  
  60.     if(x=7)
  61.        {printf("foo");
  62.         }
  63.  
  64. will notice that the assignment always returns a true value and so will 
  65. just call printf() without bothering to perform the assignment.  The 
  66. obvious fix is to convert the code to
  67.  
  68.     x=7;
  69.     printf("foo");
  70.  
  71. to force the assignment.  If you typed the first code fragment I would 
  72. imagine that you meant
  73.  
  74.     if(x==7)
  75.        {printf("foo");
  76.         }
  77.  
  78. which is entirely different.
  79.  
  80.  
  81. 1.1.3  Library functions
  82.  
  83.   The library functions do not always act as expected, see "libc.doc" for
  84. a complete description of the bugs and ommisions.
  85.  
  86.   The system() function always returns -1 regardless of the value 
  87. returned by the called program.
  88.  
  89.   scanf() does not support floating point numbers, see the note in the
  90. Hints section.
  91.  
  92.  
  93. 1.1.4  Clearing address registers
  94.  
  95.   The compiler can produce incorrect assembler code, for example the
  96. function
  97.  
  98.     foo()
  99.        {register char *frob;
  100.         frob = NULL;
  101.         }
  102.  
  103. will cause the assembler to complain "Addressing mode not allowed here",
  104. this can be fixed by making frob a stack based variable
  105.  
  106.     foo()
  107.        {char *frob;
  108.         frob = NULL;
  109.         }
  110.  
  111. This is caused by the use of the "clr" instruction rather than moving
  112. 0L into the register.
  113.  
  114.  
  115. 1.1.5  Program name
  116.  
  117.   When a program is started up it should have its name in argv[0], however
  118. NorthC always sets this string to "".  This will confuse some programs.
  119.  
  120.  
  121. 1.1.6  fseek()
  122.  
  123.   fseek() does not work correctly when seeking to the start of a "w+" file, 
  124. or at least when a switches from reading to writing.
  125.  
  126.  
  127. Release 1.0
  128. ***********
  129.  
  130. 1.0.1a  Declarations inside functions
  131.  
  132.   Declarations inside functions are dangerous, a definition such as
  133.  
  134.     example()
  135.        {char *ex2();
  136.         .
  137.         .
  138.         }
  139.  
  140.     char *
  141.     ex2()
  142.        {.
  143.         .
  144.         }
  145.  
  146. will fail to assemble because the predeclaration of ex2() will make the
  147. assembler think it is an external function.  This gives undefined symbol 
  148. errors at link time.  This can be solved by placing the reference to ex2()
  149. before the start of the example() function,
  150.  
  151.     char *ex2();
  152.  
  153.     example()
  154.        {.
  155.         .
  156.         }
  157.  
  158.     char *
  159.     ex2()
  160.        {.
  161.         .
  162.         }
  163.  
  164. this is due to the fact that "A68K" requires all external references to be
  165. defined.
  166.  
  167.  
  168.  
  169. Fixes
  170. *****
  171.  
  172.   Here is a list of previously noted bugs that are now fixed.
  173.  
  174. Release 1.1
  175. ***********
  176.  
  177. 1.0.1b  Declarations inside functions
  178.  
  179.   The bug that made static variables defined in functions crash the linker
  180. has been fixed.  You can now write
  181.  
  182.     example()
  183.        {static int jim;
  184.         .
  185.         .
  186.         }
  187.  
  188. without crashing the linker or having the created program skip functions
  189. on the return stack.
  190.  
  191.  
  192. Hints
  193. *****
  194.  
  195.  
  196.   Large numbers of functions have not yet been implemeneted, or behave 
  197. differently from ANSI, see the "libc.doc" file for details.  If you find any
  198. functions that you really need are not yet done you will have to write 
  199. them yourself.
  200.  
  201.  
  202.  
  203.   Integers are 16 bits, this causes problems in porting programs from some 
  204. compilers where integers and longs are the same size.  For example
  205.  
  206.     bar(jim)
  207.         int jim;
  208.        {.
  209.         .
  210.         }
  211.  
  212.     long foo;
  213.  
  214.     ex()
  215.        {.
  216.         .
  217.         bar(foo+4);
  218.         .
  219.         .
  220.         }
  221.  
  222. will not work, bar() will always take just the top 16 bits of the argument
  223. it is passed.  Make sure you know if you are dealing with an integer or long.
  224.  
  225.   NOTE in the standard NorthC library all AmigaDOS functions require 32 bit 
  226. values, if you call them with "int"s they will get confused and probably 
  227. summon the guru.
  228.  
  229.  
  230.  
  231.   scanf() and all its relatives, behave in counter intuitive ways.  If you
  232. use these functions you might have problems getting programs to work, and
  233. you will certainly have problems porting your programs between machines, I
  234. know for sure that there is a difference between NorthC scanf() and the one
  235. in UNIX V.  I might not fix this problem, I have yet to find two versions
  236. of 'C' that do the same thing with scanf(), I would recommend you just don't
  237. use it.
  238.  
  239.  
  240.  
  241.   If the compiler suddenly starts crashing the machine whenever it is run
  242. check how full the disk is.  If the OS returns a "disk full" error the 
  243. compiler may just carry on writing to the disk regardless.
  244.  
  245.  
  246.  
  247.   If your program dies with a message like "Error: 1004" this indicates a
  248. library error, look in the ":include/errno.h" file to find out what the
  249. library function is complaining about, or use the strerror() function.
  250.  
  251.  
  252.  
  253.   The compiler examines the value of the "INCLUDE" environment variable
  254. and adds the listed directories to its include directories.  Separate
  255. directories should have a ',' character between them.  For example to
  256. look on the directories "df1:foo" "//jim" and "fred" issue the CLI command 
  257.  
  258.     setenv INCLUDE "df1:foo,//jim,fred"
  259.  
  260. this feature has not been fully tested yet so it may be interesting to
  261. use.
  262.  
  263.  
  264.  
  265.   Here is a clasic mistake that all real 'C' programmers must make at least 
  266. once, beware of the difference between
  267.  
  268.     if(jim==foo())
  269.        {.
  270.         .
  271.         }
  272.  
  273. and
  274.  
  275.     if(jim=foo())
  276.        {.
  277.         .
  278.         }
  279.  
  280. one of these is an assignment the other is a test, both are valid 'C'.  
  281. Some programmers guard against this by using
  282.  
  283.     #define EQ ==
  284.     .
  285.     .
  286.     if(jim EQ foo())
  287.        {.
  288.         .
  289.         }
  290.  
  291. of course you would put the first definition in an include file, "easyC.h"
  292. for example.
  293.  
  294.  
  295.  
  296.   Large programs may cause Blink to have some problems, if you find that
  297. some symbols refuse to link in very large programs try setting the 
  298. "SMALLCODE" flag.  If you keep finding that Blink is failing
  299. to link symbols you know are defined try linking with the command
  300.  
  301.     cc -ooutname -bSMALLCODE foo.o bar.o baz.o
  302.  
  303. this fixes the problem for my largest program, NorthC.
  304.  
  305.   In general if the linker is causing problems it is worth setting it to
  306. verbose, us a command such as
  307.  
  308.     cc -ooutname -bVERBOSE foo.o bar.o baz.o
  309.  
  310. this will at least give a clue as to where the linker problem was.
  311.  
  312.  
  313.  
  314.   There is no way at the moment to handle interrupts within NorthC, this
  315. should be fixed when I find a book that explains what to do to handle them 
  316. in AmigaDOS.
  317.  
  318.  
  319.  
  320.   If you want to see how to write assembler that 'C' can call use the 
  321. "-s" option to "cc" to get hold of the intermediate assembler file then 
  322. edit that.  "cc" knows that .s files just need to be assembled.  
  323.  
  324.   Look at "crt0.asm" to see how I have used the assembler, there may be 
  325. some good ideas to steal.
  326.  
  327.   When writing assembler be sure to restore the registers before you 
  328. return, NorthC expects you to alter the registers d0 d1 a0 and a1 but any 
  329. other registers must be restored or else very nasty things can happen.
  330.  
  331.   If you want to play with the low levels of the operating system I would 
  332. recommend that you use the debug() routine a lot.
  333.  
  334.  
  335.  
  336.   Here is another classic 'C' mistake,
  337.  
  338.     jim = 4;
  339.     joe = jim<<2 + 3;
  340.  
  341. this will set joe to 128, not 19 as you might expect (well I would).  When
  342. using the shift operator always put brackets to make the nesting obvious.
  343.  
  344.  
  345.  
  346.   Array indecies always start at 0 and go up to the number of elements minus
  347. one.
  348.