On Apr 26, 2009, at 1:06 AM, Albert Cahalan wrote:

As you noticed, weird things can happen. :-(

For MacOS, don't define anything to indicate
BSD or POSIX source. That would break stuff.

Actually since MacOS X is both POSIX-compliant and FreeBSD-based, both work perfectly fine.


For Linux, the FSF bastards demand _GNU_SOURCE
as part of their plan to give Linux an ugly name.

I suggest:

-std=gnu99 (accept modern code)
-D_GNU_SOURCE (satisfy Stallman's ego)
-O2, -O3, or -Os (required for some warnings!)
-Wl,-warn-common (warn about UNIX-only C feature)

This will pass -warn-common to the linker. On MacOS X, the linker uses -warn_commons.


-fno-common (block that UNIX-only C feature)
-ffast-math (allow algebraic simplification)

This doesn't allow algebraic simplification. It allows evaluation of certain math operations to not be as precise so they can run faster. For OpenOCD it probably won't matter (nor will it really do much to improve performance). For anything that does lots of floating point math, it _can_ improve performance, but the results need to be verified after turning it on.


-Wall (most useful warnings)
-W (more useful warnings)
-Wshadow (shadowing confuses people: bugs)
-Wcast-align (not portable)
-Wredundant-decls (find missing header protection)
-Wbad-function-cast
-Wcast-qual
-Waggregate-return (code may be slow)
-Wstrict-prototypes (very important for quality C)
-Wmissing-prototypes (very important for quality C)

If not debugging:

-s (make executable file smaller)

Strips all symbol and relocation information. Depending on the tools, this can make debugging or profiling much more challenging.


-fomit-frame-pointer (make code smaller and faster)

Also makes profiling nearly impossible without unwinding information. That is included with DWARF, but not STABs. Even with DWARF, not all tools can use it (see kernel-based profilers).



If debugging:

-g3 (the "3" gets you line info)

The 3 gets you macro expansion if your debugger supports it. I don't think GDB does.



If you truly must support ancient compilers:

-Wdeclaration-after-statement (ouch)

If the compiler accepts the option:

-Wstrict-aliasing (catch horrible bugs)
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

--
Rick Altherr
kc8...@kc8apf.net

"He said he hadn't had a byte in three days. I had a short, so I split it with him."
-- Unsigned



Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to