gcc/gcc
Oleg Endo decc676eb5 re PR target/49880 (SuperH: ICE when -m4 is used with -mdiv=call-div1)
PR target/49880
	* config/sh/sh.opt (FPU_SINGLE_ONLY): New mask.
	(musermode): Convert to Var(TARGET_USERMODE).
	* config/sh/sh.h (SELECT_SH2A_SINGLE_ONLY, SELECT_SH4_SINGLE_ONLY,
	MASK_ARCH): Add MASK_FPU_SINGLE_ONLY.
	* config/sh/sh.c (sh_option_override): Use
	TARGET_FPU_DOUBLE || TARGET_FPU_SINGLE_ONLY for call-fp case.
	* config/sh/sh.md (udivsi3_i1, divsi3_i1): Remove ! TARGET_SH4
	condition.
	(udivsi3_i4, divsi3_i4): Use TARGET_FPU_DOUBLE condition instead of
	TARGET_SH4.
	(udivsi3_i4_single, divsi3_i4_single): Use
	TARGET_FPU_SINGLE_ONLY || TARGET_FPU_DOUBLE instead of TARGET_HARD_SH4.

	PR target/49880
	* config/sh/lib1funcs.S (sdivsi3_i4, udivsi3_i4): Enable for SH2A.
	(sdivsi3, udivsi3): Remove SH4 check and always compile these functions.

	PR target/49880
	* gcc.target/sh/pr49880-1.c: New.
	* gcc.target/sh/pr49880-2.c: New.
	* gcc.target/sh/pr49880-3.c: New.
	* gcc.target/sh/pr49880-4.c: New.
	* gcc.target/sh/pr49880-5.c: New.

From-SVN: r196636
2013-03-13 18:09:10 +00:00
..
ada re PR ada/52123 (gcc bootstrap with ada fails on mingw target) 2013-03-08 08:04:00 +00:00
c
c-family re PR middle-end/56524 (Compiler ICE when compiling with -mips16) 2013-03-09 07:54:02 +00:00
common
config re PR target/49880 (SuperH: ICE when -m4 is used with -mdiv=call-div1) 2013-03-13 18:09:10 +00:00
cp re PR c++/56567 (ICE with lambda return type deduction and braced-init-list) 2013-03-11 12:22:16 -04:00
doc * doc/invoke.texi (-Waddr-space-convert): Move into the table earlier. 2013-03-12 14:25:01 +01:00
fortran gfortran.texi (STRUCTURE and RECORD): State more clearly how to convert them into derived types. 2013-03-11 19:37:30 +01:00
ginclude
go
java
lto
objc
objcp
po * de.po, sv.po: Update. 2013-03-11 15:24:43 +00:00
testsuite re PR target/49880 (SuperH: ICE when -m4 is used with -mdiv=call-div1) 2013-03-13 18:09:10 +00:00
ABOUT-GCC-NLS
acinclude.m4
aclocal.m4
addresses.h
alias.c * alias.c (init_alias_analysis): Clear reg_known_equiv_p bitmap. 2013-03-05 10:40:38 +01:00
alias.h
alloc-pool.c
alloc-pool.h
asan.c
asan.h
attribs.c
auto-inc-dec.c
BASE-VER
basic-block.h
bb-reorder.c
bb-reorder.h
bitmap.c bitmap.c (struct bitmap_descriptor_d): Use unsigned HOST_WIDEST_INT for all counters. 2013-03-07 17:27:52 +00:00
bitmap.h
bt-load.c
builtin-attrs.def
builtin-types.def
builtins.c
builtins.def
builtins.h
caller-save.c
calls.c
cfg-flags.def
cfg.c
cfganal.c
cfgbuild.c
cfgcleanup.c
cfgexpand.c re PR debug/56510 (More var-tracking scalability problems) 2013-03-05 23:31:50 +01:00
cfghooks.c
cfghooks.h
cfgloop.c
cfgloop.h
cfgloopanal.c
cfgloopmanip.c
cfgrtl.c
cgraph.c
cgraph.h
cgraphbuild.c
cgraphclones.c
cgraphunit.c
ChangeLog re PR target/49880 (SuperH: ICE when -m4 is used with -mdiv=call-div1) 2013-03-13 18:09:10 +00:00
ChangeLog-1997
ChangeLog-1998
ChangeLog-1999
ChangeLog-2000
ChangeLog-2001
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog.dataflow
ChangeLog.graphite
ChangeLog.lib
ChangeLog.ptr
ChangeLog.tree-ssa
ChangeLog.tuples
cif-code.def
collect2-aix.c
collect2-aix.h
collect2.c
collect2.h
combine-stack-adj.c
combine.c
common.opt
compare-elim.c
conditions.h
config.build
config.gcc re PR plugins/45078 (config/vxworks-dummy.h not installed as a plugin header on some archs) 2013-03-13 10:47:41 +01:00
config.host
config.in
configure
configure.ac
convert.c
convert.h
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
coretypes.h
coverage.c
coverage.h
cppbuiltin.c
cppbuiltin.h
cppdefault.c
cppdefault.h
cprop.c
cse.c
cselib.c
cselib.h
cstamp-h.in
data-streamer-in.c
data-streamer-out.c
data-streamer.c
data-streamer.h
DATESTAMP Daily bump. 2013-03-13 00:19:53 +00:00
dbgcnt.c
dbgcnt.def
dbgcnt.h
dbxout.c
dbxout.h
dce.c
dce.h
ddg.c
ddg.h
debug.c
debug.h
defaults.h
DEV-PHASE
df-core.c
df-problems.c
df-scan.c
df.h
dfp.c
dfp.h
diagnostic-core.h
diagnostic.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-04 22:52:08 +01:00
diagnostic.def
diagnostic.h
dojump.c
dominance.c
domwalk.c
domwalk.h
double-int.c
double-int.h
dse.c dse.c (delete_dead_store_insn): Respect TDF_DETAILS. 2013-03-09 22:04:15 +00:00
dumpfile.c
dumpfile.h
dwarf2asm.c
dwarf2asm.h
dwarf2cfi.c
dwarf2out.c re PR debug/55364 (ICE: in remove_addr_table_entry, at dwarf2out.c:4201 with -O -gsplit-dwarf) 2013-03-05 15:08:45 -08:00
dwarf2out.h
emit-rtl.c re PR rtl-optimization/56571 (ICE in copyprop_hardreg_forward_1, at regcprop.c (insn does not satisfy its constraints !)) 2013-03-12 12:13:33 +00:00
emit-rtl.h
errors.c
errors.h
et-forest.c
et-forest.h
except.c re PR c++/55135 (Segfault of gcc on a big file) 2013-03-05 14:45:23 +00:00
except.h re PR c++/55135 (Segfault of gcc on a big file) 2013-03-05 14:45:23 +00:00
exec-tool.in
explow.c
expmed.c
expmed.h
expr.c re PR middle-end/56548 (ICE in emit_move_insn, at expr.c:3486 with -march=pentium{pro,2,3} -O3) 2013-03-06 18:18:46 +01:00
expr.h
file-find.c
file-find.h
final.c
fixed-value.c
fixed-value.h
flag-types.h
flags.h
fold-const.c
fp-test.c
FSFChangeLog
FSFChangeLog.10
FSFChangeLog.11
function.c re PR middle-end/56524 (Compiler ICE when compiling with -mips16) 2013-03-09 07:54:02 +00:00
function.h re PR middle-end/56524 (Compiler ICE when compiling with -mips16) 2013-03-09 07:54:02 +00:00
fwprop.c
gcc-ar.c
gcc-plugin.h
gcc.c re PR lto/50293 (-flto fails if GCC is installed in directory with space in path name) 2013-03-06 06:32:03 +00:00
gcc.h
gcov-dump.c
gcov-io.c
gcov-io.h
gcov-iov.c
gcov.c
gcse.c
gcse.h
gdbinit.in
genattr-common.c
genattr.c
genattrtab.c
genautomata.c
gencheck.c
genchecksum.c
gencodes.c
genconditions.c
genconfig.c
genconstants.c
genemit.c
genenums.c
genextract.c
genflags.c
gengenrtl.c
gengtype-lex.l
gengtype-parse.c
gengtype-state.c
gengtype.c
gengtype.h
genhooks.c
genmddeps.c
genmddump.c
genmodes.c
genmultilib
genopinit.c
genoutput.c
genpeep.c
genpreds.c
genrecog.c
gensupport.c
gensupport.h
ggc-common.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 16:51:48 +01:00
ggc-internal.h
ggc-none.c
ggc-page.c
ggc.h
gimple-fold.c
gimple-fold.h
gimple-iterator.c
gimple-low.c
gimple-pretty-print.c trans-mem.c (expand_transaction): Do not set PR_INSTRUMENTEDCODE if GTMA_HAS_NO_INSTRUMENTATION. 2013-03-08 22:26:37 +00:00
gimple-pretty-print.h
gimple-ssa-strength-reduction.c
gimple-streamer-in.c
gimple-streamer-out.c
gimple-streamer.h
gimple.c
gimple.def
gimple.h trans-mem.c (expand_transaction): Do not set PR_INSTRUMENTEDCODE if GTMA_HAS_NO_INSTRUMENTATION. 2013-03-08 22:26:37 +00:00
gimplify.c
glimits.h
godump.c
graph.c
graph.h
graphds.c
graphds.h
graphite-blocking.c
graphite-clast-to-gimple.c
graphite-clast-to-gimple.h
graphite-dependences.c
graphite-interchange.c
graphite-optimize-isl.c
graphite-poly.c
graphite-poly.h
graphite-scop-detection.c
graphite-scop-detection.h
graphite-sese-to-poly.c
graphite-sese-to-poly.h
graphite.c
gsstruct.def
gstab.h
gsyms.h
gsyslimits.h
gtm-builtins.def
haifa-sched.c
hard-reg-set.h
hash-table.c
hash-table.h
highlev-plugin-common.h
hooks.c
hooks.h
host-default.c
hosthooks-def.h
hosthooks.h
hw-doloop.c
hw-doloop.h
hwint.c
hwint.h
ifcvt.c re PR rtl-optimization/56484 (ICE in assign_by_spills, at lra-assigns.c:1268) 2013-03-05 23:25:43 +01:00
incpath.c
incpath.h
init-regs.c
input.c
input.h
insn-addr.h
insn-notes.def
internal-fn.c
internal-fn.def
internal-fn.h
intl.c
intl.h
ipa-cp.c
ipa-inline-analysis.c
ipa-inline-transform.c
ipa-inline.c
ipa-inline.h
ipa-prop.c
ipa-prop.h
ipa-pure-const.c
ipa-ref-inline.h
ipa-ref.c
ipa-ref.h
ipa-reference.c
ipa-reference.h
ipa-split.c re PR tree-optimization/56424 (ICE at tree-inline.c:2833 on a-nllcef.ads at -O2) 2013-03-04 17:41:32 +00:00
ipa-utils.c
ipa-utils.h
ipa.c
ira-build.c
ira-color.c
ira-conflicts.c
ira-costs.c
ira-emit.c
ira-int.h
ira-lives.c
ira.c
ira.h
is-a.h
jump.c
langhooks-def.h
langhooks.c
langhooks.h
LANGUAGES
lcm.c
libfuncs.h
limitx.h
limity.h
lists.c
loop-doloop.c
loop-init.c re PR middle-end/56525 (Access to ggc_freed memory in flow_loops_find) 2013-03-05 12:51:28 +00:00
loop-invariant.c
loop-iv.c
loop-unroll.c
loop-unswitch.c
lower-subreg.c
lower-subreg.h
lra-assigns.c
lra-coalesce.c
lra-constraints.c
lra-eliminations.c
lra-int.h
lra-lives.c
lra-spills.c
lra.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 16:50:38 +01:00
lra.h
lto-cgraph.c
lto-compress.c
lto-compress.h
lto-opts.c
lto-section-in.c
lto-section-out.c
lto-streamer-in.c
lto-streamer-out.c re PR libstdc++/56557 (Link error about std::fstream' or std::stringstream' with -flto' and -rdynamic' options) 2013-03-12 12:38:47 +00:00
lto-streamer.c
lto-streamer.h
lto-symtab.c
lto-wrapper.c
machmode.def
machmode.h
main.c
Makefile.in Makefile.in (dg_target_exps): Add aarch64.exp, epiphany.exp and tic6x.exp. 2013-03-05 10:46:34 +01:00
mcf.c
mkconfig.sh
mode-classes.def
mode-switching.c
modulo-sched.c
omega.c
omega.h
omp-builtins.def
omp-low.c
ONEWS
opt-functions.awk
opt-gather.awk
opt-include.awk
opt-read.awk
optabs.c re PR middle-end/56524 (Compiler ICE when compiling with -mips16) 2013-03-09 07:54:02 +00:00
optabs.def
optabs.h
optc-gen.awk
optc-save-gen.awk
opth-gen.awk
opts-common.c re PR bootstrap/56509 (gnattools build failure) 2013-03-05 07:01:13 +01:00
opts-diagnostic.h
opts-global.c
opts.c re PR bootstrap/56509 (gnattools build failure) 2013-03-05 07:01:13 +01:00
opts.h
output.h
params.c
params.def
params.h
passes.c
plugin.c
plugin.def
plugin.h
pointer-set.c
pointer-set.h
postreload-gcse.c
postreload.c
predict.c re PR tree-optimization/56478 (ICE: Floating point exception in tree_estimate_probability) 2013-03-08 14:41:14 +00:00
predict.def
predict.h
prefix.c
prefix.h
pretty-print.c
pretty-print.h
print-rtl.c
print-tree.c
profile.c
profile.h
read-md.c
read-md.h
read-rtl.c
README.Portability
real.c
real.h
realmpfr.c
realmpfr.h
recog.c
recog.h
ree.c
reg-notes.def
reg-stack.c
regcprop.c
reginfo.c
regmove.c
regrename.c
regrename.h
regs.h
regset.h
regstat.c
reload1.c
reload.c
reload.h
reorg.c
resource.c
resource.h
rtl-error.c
rtl-error.h
rtl.c re PR rtl-optimization/56571 (ICE in copyprop_hardreg_forward_1, at regcprop.c (insn does not satisfy its constraints !)) 2013-03-12 12:13:33 +00:00
rtl.def
rtl.h
rtlanal.c
rtlhooks-def.h
rtlhooks.c
sanitizer.def
sbitmap.c
sbitmap.h
sched-deps.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 16:49:43 +01:00
sched-ebb.c
sched-int.h
sched-rgn.c
sched-vis.c
sdbout.c sdbout.c (sdbout_one_type): Switch to current function's section supporting cold/hot. 2013-03-05 18:59:38 +01:00
sdbout.h
sel-sched-dump.c
sel-sched-dump.h
sel-sched-ir.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 07:02:36 +01:00
sel-sched-ir.h
sel-sched.c
sel-sched.h
sese.c
sese.h
simplify-rtx.c re PR rtl-optimization/56494 (ICE in simplify_truncation, at simplify-rtx.c:619) 2013-03-05 07:04:14 +01:00
sparseset.c
sparseset.h
sreal.c
sreal.h
ssaexpand.h
stab.def
stack-ptr-mod.c
statistics.c
statistics.h
stmt.c
stor-layout.c
store-motion.c
streamer-hooks.c
streamer-hooks.h
stringpool.c
symtab.c
sync-builtins.def
system.h
target-def.h
target-globals.c
target-globals.h
target-hooks-macros.h
target.def target.def (TARGET_OPTION_VALID_ATTRIBUTE_P): Update comments; the attribute is now called "target" instead of "option". 2013-03-03 15:21:26 -05:00
target.h
targhooks.c
targhooks.h
timevar.c
timevar.def
timevar.h
tlink.c
toplev.c
toplev.h
tracer.c
trans-mem.c trans-mem.c (expand_transaction): Do not set PR_INSTRUMENTEDCODE if GTMA_HAS_NO_INSTRUMENTATION. 2013-03-08 22:26:37 +00:00
trans-mem.h
tree-affine.c
tree-affine.h
tree-browser.c
tree-browser.def
tree-call-cdce.c
tree-cfg.c re PR lto/56570 (ICE when streaming a TREE_BLOCK) 2013-03-08 13:46:18 +00:00
tree-cfgcleanup.c
tree-chrec.c
tree-chrec.h
tree-complex.c
tree-data-ref.c
tree-data-ref.h
tree-dfa.c tree-dfa.c (get_or_create_ssa_default_def): Use parameter fn in all appropriate places. 2013-03-04 19:49:59 +01:00
tree-diagnostic.c
tree-diagnostic.h
tree-dump.c
tree-dump.h
tree-eh.c re PR c++/55135 (Segfault of gcc on a big file) 2013-03-05 14:45:23 +00:00
tree-emutls.c
tree-flow-inline.h
tree-flow.h
tree-if-conv.c
tree-inline.c tree-inline.c (expand_call_inline): Do not associate a BLOCK with the location in BLOCK_SOURCE_LOCATION. 2013-03-08 11:29:06 +00:00
tree-inline.h
tree-into-ssa.c re PR tree-optimization/56294 (BOOT_CFLAGS='-O2 -g -fno-ipa-sra' leads to bootstrap comparison failure) 2013-03-06 11:24:07 +00:00
tree-iterator.c
tree-iterator.h
tree-loop-distribution.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-04 11:08:57 +01:00
tree-mudflap.c
tree-mudflap.h
tree-nested.c
tree-nomudflap.c
tree-nrv.c
tree-object-size.c
tree-optimize.c
tree-outof-ssa.c
tree-parloops.c
tree-pass.h
tree-phinodes.c
tree-predcom.c
tree-pretty-print.c
tree-pretty-print.h
tree-profile.c
tree-scalar-evolution.c
tree-scalar-evolution.h
tree-sra.c re PR lto/56570 (ICE when streaming a TREE_BLOCK) 2013-03-08 13:46:18 +00:00
tree-ssa-address.c
tree-ssa-alias.c
tree-ssa-alias.h
tree-ssa-ccp.c
tree-ssa-coalesce.c
tree-ssa-copy.c
tree-ssa-copyrename.c
tree-ssa-dce.c
tree-ssa-dom.c
tree-ssa-dse.c
tree-ssa-forwprop.c
tree-ssa-ifcombine.c
tree-ssa-live.c
tree-ssa-live.h
tree-ssa-loop-ch.c
tree-ssa-loop-im.c
tree-ssa-loop-ivcanon.c
tree-ssa-loop-ivopts.c
tree-ssa-loop-manip.c
tree-ssa-loop-niter.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 10:38:48 +01:00
tree-ssa-loop-prefetch.c
tree-ssa-loop-unswitch.c
tree-ssa-loop.c
tree-ssa-math-opts.c
tree-ssa-operands.c
tree-ssa-operands.h
tree-ssa-phiopt.c
tree-ssa-phiprop.c
tree-ssa-pre.c
tree-ssa-propagate.c
tree-ssa-propagate.h
tree-ssa-reassoc.c re PR middle-end/56559 (ICE in propagate_op_to_single_use, at tree-ssa-reassoc.c:1057) 2013-03-07 15:34:15 +01:00
tree-ssa-sccvn.c re PR tree-optimization/56521 (Uninitialized value_id) 2013-03-05 15:02:58 +00:00
tree-ssa-sccvn.h
tree-ssa-sink.c
tree-ssa-strlen.c
tree-ssa-structalias.c
tree-ssa-tail-merge.c
tree-ssa-ter.c tree-ssa-ter.c (is_replaceable_p): Do not TER across location or block changes with -Og. 2013-03-08 08:45:29 +00:00
tree-ssa-threadedge.c
tree-ssa-threadupdate.c
tree-ssa-uncprop.c
tree-ssa-uninit.c
tree-ssa.c
tree-ssanames.c
tree-stdarg.c
tree-stdarg.h
tree-streamer-in.c
tree-streamer-out.c
tree-streamer.c
tree-streamer.h
tree-switch-conversion.c
tree-tailcall.c re PR tree-optimization/56539 (ICE: verify_ssa failed: caused by -foptimize-sibling-calls) 2013-03-07 00:26:42 +01:00
tree-vect-data-refs.c re PR lto/50494 (gcc.dg/vect/vect-reduc-2char.c fails spuriously on ppc with -flto) 2013-03-06 08:38:46 +00:00
tree-vect-generic.c
tree-vect-loop-manip.c
tree-vect-loop.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 10:37:56 +01:00
tree-vect-patterns.c
tree-vect-slp.c re PR tree-optimization/56608 (SLP seems to produce incorrect value with -ffast-math) 2013-03-13 12:15:06 +00:00
tree-vect-stmts.c re PR middle-end/56461 (GCC is leaking lots of memory) 2013-03-05 10:37:56 +01:00
tree-vectorizer.c
tree-vectorizer.h
tree-vrp.c
tree.c
tree.def
tree.h re PR middle-end/56524 (Compiler ICE when compiling with -mips16) 2013-03-09 07:54:02 +00:00
treestruct.def
tsan.c
tsan.h
tsystem.h
typeclass.h
valtrack.c re PR rtl-optimization/56571 (ICE in copyprop_hardreg_forward_1, at regcprop.c (insn does not satisfy its constraints !)) 2013-03-12 12:13:33 +00:00
valtrack.h
value-prof.c
value-prof.h
var-tracking.c
varasm.c re PR lto/50494 (gcc.dg/vect/vect-reduc-2char.c fails spuriously on ppc with -flto) 2013-03-06 08:38:46 +00:00
varpool.c
vec.c
vec.h
version.c
version.h
vmsdbg.h
vmsdbgout.c
web.c
xcoff.h
xcoffout.c
xcoffout.h

Copyright (C) 2000-2013 Free Software Foundation, Inc.

This file is intended to contain a few notes about writing C code
within GCC so that it compiles without error on the full range of
compilers GCC needs to be able to compile on.

The problem is that many ISO-standard constructs are not accepted by
either old or buggy compilers, and we keep getting bitten by them.
This knowledge until know has been sparsely spread around, so I
thought I'd collect it in one useful place.  Please add and correct
any problems as you come across them.

I'm going to start from a base of the ISO C90 standard, since that is
probably what most people code to naturally.  Obviously using
constructs introduced after that is not a good idea.

For the complete coding style conventions used in GCC, please read
http://gcc.gnu.org/codingconventions.html


String literals
---------------

Irix6 "cc -n32" and OSF4 "cc" have problems with constant string
initializers with parens around it, e.g.

const char string[] = ("A string");

This is unfortunate since this is what the GNU gettext macro N_
produces.  You need to find a different way to code it.

Some compilers like MSVC++ have fairly low limits on the maximum
length of a string literal; 509 is the lowest we've come across.  You
may need to break up a long printf statement into many smaller ones.


Empty macro arguments
---------------------

ISO C (6.8.3 in the 1990 standard) specifies the following:

If (before argument substitution) any argument consists of no
preprocessing tokens, the behavior is undefined.

This was relaxed by ISO C99, but some older compilers emit an error,
so code like

#define foo(x, y) x y
foo (bar, )

needs to be coded in some other way.


Avoid unnecessary test before free
----------------------------------

Since SunOS 4 stopped being a reasonable portability target,
(which happened around 2007) there has been no need to guard
against "free (NULL)".  Thus, any guard like the following
constitutes a redundant test:

  if (P)
    free (P);

It is better to avoid the test.[*]
Instead, simply free P, regardless of whether it is NULL.

[*] However, if your profiling exposes a test like this in a
performance-critical loop, say where P is nearly always NULL, and
the cost of calling free on a NULL pointer would be prohibitively
high, consider using __builtin_expect, e.g., like this:

  if (__builtin_expect (ptr != NULL, 0))
    free (ptr);



Trigraphs
---------

You weren't going to use them anyway, but some otherwise ISO C
compliant compilers do not accept trigraphs.


Suffixes on Integer Constants
-----------------------------

You should never use a 'l' suffix on integer constants ('L' is fine),
since it can easily be confused with the number '1'.


			Common Coding Pitfalls
			======================

errno
-----

errno might be declared as a macro.


Implicit int
------------

In C, the 'int' keyword can often be omitted from type declarations.
For instance, you can write

  unsigned variable;

as shorthand for

  unsigned int variable;

There are several places where this can cause trouble.  First, suppose
'variable' is a long; then you might think

  (unsigned) variable

would convert it to unsigned long.  It does not.  It converts to
unsigned int.  This mostly causes problems on 64-bit platforms, where
long and int are not the same size.

Second, if you write a function definition with no return type at
all:

  operate (int a, int b)
  {
    ...
  }

that function is expected to return int, *not* void.  GCC will warn
about this.

Implicit function declarations always have return type int.  So if you
correct the above definition to

  void
  operate (int a, int b)
  ...

but operate() is called above its definition, you will get an error
about a "type mismatch with previous implicit declaration".  The cure
is to prototype all functions at the top of the file, or in an
appropriate header.

Char vs unsigned char vs int
----------------------------

In C, unqualified 'char' may be either signed or unsigned; it is the
implementation's choice.  When you are processing 7-bit ASCII, it does
not matter.  But when your program must handle arbitrary binary data,
or fully 8-bit character sets, you have a problem.  The most obvious
issue is if you have a look-up table indexed by characters.

For instance, the character '\341' in ISO Latin 1 is SMALL LETTER A
WITH ACUTE ACCENT.  In the proper locale, isalpha('\341') will be
true.  But if you read '\341' from a file and store it in a plain
char, isalpha(c) may look up character 225, or it may look up
character -31.  And the ctype table has no entry at offset -31, so
your program will crash.  (If you're lucky.)

It is wise to use unsigned char everywhere you possibly can.  This
avoids all these problems.  Unfortunately, the routines in <string.h>
take plain char arguments, so you have to remember to cast them back
and forth - or avoid the use of strxxx() functions, which is probably
a good idea anyway.

Another common mistake is to use either char or unsigned char to
receive the result of getc() or related stdio functions.  They may
return EOF, which is outside the range of values representable by
char.  If you use char, some legal character value may be confused
with EOF, such as '\377' (SMALL LETTER Y WITH UMLAUT, in Latin-1).
The correct choice is int.

A more subtle version of the same mistake might look like this:

  unsigned char pushback[NPUSHBACK];
  int pbidx;
  #define unget(c) (assert(pbidx < NPUSHBACK), pushback[pbidx++] = (c))
  #define get(c) (pbidx ? pushback[--pbidx] : getchar())
  ...
  unget(EOF);

which will mysteriously turn a pushed-back EOF into a SMALL LETTER Y
WITH UMLAUT.


Other common pitfalls
---------------------

o Expecting 'plain' char to be either sign or unsigned extending.

o Shifting an item by a negative amount or by greater than or equal to
  the number of bits in a type (expecting shifts by 32 to be sensible
  has caused quite a number of bugs at least in the early days).

o Expecting ints shifted right to be sign extended.

o Modifying the same value twice within one sequence point.

o Host vs. target floating point representation, including emitting NaNs
  and Infinities in a form that the assembler handles.

o qsort being an unstable sort function (unstable in the sense that
  multiple items that sort the same may be sorted in different orders
  by different qsort functions).

o Passing incorrect types to fprintf and friends.

o Adding a function declaration for a module declared in another file to
  a .c file instead of to a .h file.