Some common errors, error messages, frequently asked questions
==============================================================

Make sure you have a .section ".text" 
    - especially if they do have a .section ".data"
    - no spaces between the quotes

Make sure you put all data (format strings, etc.) in
the .section ".data" section and *NOT* in the text section!

This can throw off the instruction alignment if you put data
in the text section.

----------------------------

Make sure you have a function prototype in scope for
every function (no matter what language the function is
written in) that you call from C code. The C compiler relies
on the function prototype to properly convert/pass arguments and
retrieve the return value.

----------------------------

Closing comment of "* /" vs. "*/"
    - syntax highlighting in vim would show this

----------------------------

Lint message:
  "Defined global, could be defined static"

Commonly something like:

	FILE *stdError = stderr;

and then use stdError (vs. stderr) elsewhere in main().

Change use of stdError elsewhere in main() to use stderr (preferred).

  or

Use "-m" lint flag:
     -m   Suppress complaints about external symbols that could
          be declared static.


----------------------------

ld: printChar.o(.text+0x4): relocation truncated to fit: R_SPARC_13 data
    - using mov instead of set with a label or large constant > +/-4K

	mov	fmt, %o0	should be	set	fmt, %o0

	mov	5555, %l0	should be	set	5555, %l0

    - 2nd source operand a label or large constant > +/-4K

	add	%l0, 5555, %l1	should be	set	5555, %l2
						add	%l0, %l2, %l1

----------------------------

Misspelled or wrong name in .global and/or function_label:

----------------------------

Not having a save and ret/restore

----------------------------

Not having a nop in the delay slot after each call and branch instruction

----------------------------

Incorrect formula/number in save

Make sure you are ANDing with -8 and not 8

	save	%sp, -( 92 + LOCAL_VARIABLE_SPACE ) & -8, %sp

----------------------------

Incorrect dereferencing / number of ld's

----------------------------

Lint error:
variable unused in function
    #tmp0 in main
    lint: errors in main.c; no output created

This means a variable (even defined as const) is being used as the number
of elements in an array definition (not allowed in strict ANSI C). 
Must use a #define instead.

	const int ARRAY_SIZE = 10;
	int array[ARRAY_SIZE];     <<<<<<<<<< Error

change to

	#define ARRAY_SIZE 10
	int array[ARRAY_SIZE];

----------------------------

Make sure you have separate .section ".data" and ".text" -- do not combine
them.

----------------------------

'\0' vs. '\0000'  for nul char. -- better to use %g0

	'\0' is interpreted as the char. '0' or string "0"
	'\0xxx' indicates octal ASCII value
	again - better to use %g0

	'\n' is fine.

----------------------------

Using Uppercase O vs. Zero

Using Ox (Uppercase O) vs 0x (Zero)

Using %gO or %oO or %lO (Uppercase O) vs %g0 or %o0 or %l0 (Zero)

----------------------------

Use:
    gdb a.out core
      where

----------------------------

gcc: Internal error: Segmentation fault (program as)

Crashing the assembler!

You most likely have an assembler statement that is syntactically
malformed.  Commonly a pseudo-op that requires one operand but you
supply it with mulitple operands like:

	clr	%l0, %l1, %l2

should be

	clr	%l0
	clr	%l1
	clr	%l2

or

	mov	%l0, %l1, %l2

should be

	mov	%l0, %l1

etc.

----------------------------