[Geany] [PATCH] Fixes for warnings and portability

Daniel Richard G. skunk at xxxxx
Sun Feb 17 05:43:56 UTC 2008


I normally build software with many warnings turned on, and also frequently 
build on non-Linux Unix platforms. In the course of doing both with Geany, 
I came across many warnings and portability issues that the attached patch 
seeks to address.

Below is a walkthrough of the changes. I'll describe each sort of change 
only once, the first time it occurs in the patch file, for brevity:

* (various files): Anytime you have a prototype/definition of a function
  that doesn't take arguments, use (void) instead of (). This eliminates 
  the "function declaration isn't a prototype" warning.

* highlighting.c: Bitfields in structs should properly have a full integer
  type.

* highlighting.c: Declaring these HighlightingStyle structures as "static" 
  gets rid of "initializer element is not computable at load time" when 
  they are used in the subsequent entries[] array.

* keybindings.c: Definition of keys[] moved here from keybindings.h. (See 
  below for explanation)

* keybindings.c: Replaced the floating-point bit with a bit of integer 
  math. This parameter is supposed to be an int, so you want to keep it an 
  int.

* highlighting.h: The "gboolean" type already indicates that these fields 
  are true-false flags, and GCC complains about portability if a bitfield 
  specifier is used.

* keybindings.h: Declare, don't define, the keys[] array here. Otherwise, 
  you'll have multiple definitions of keys[] floating around (one for every 
  .c file that uses this header), and the link step will break if you use 
  -fno-common (which you should!).

* sciwrappers.c: Argument 3 to SSM() is supposed to be unsigned, so stick 
  in a cast to make it clear that what's getting passed is *not* -1.

* encodings.c: Moved the definition of the encodings[] array here from 
  encodings.h.

* encodings.c: i is unsigned, so cast that -1. (Enrico, you may want to 
  have a closer look at the logic of this loop... it seems to assume that i 
  might be (guint)-1 going in, but that's impossible, because (guint)-1 is 
  not less than GEANY_ENCODINGS_MAX.)

* encodings.c: Use the handy-dandy printf specifier for gsize that GLib 
  provides for us.

* encodings.h: Declare, don't define, the encodings[] array here.

* prefs.c: No comma after that last entry.

* dialogs.c: Cast the int to gboolean. (gboolean is probably int anyway, 
  but an explicit cast makes things clearer.)

* msgwindow.c: Using the function parameters in the initializer gives a 
  "initializer element is not computable at load time" warning, so just 
  assign them to the fields afterward.

* keyfile.c: Compounds literals look cool, but they confuse older
  compilers.

* prefix.c: Stick in a trivial bit of code to avoid an empty source file 
  when we're not building a relocatable binary.

* vte.c: Definition of vc moved here from vte.h.

* vte.h: Declare, don't define, the vc variable here.

* document.c: gchar is a signed type, so when you assign e.g. 0xef to it, 
  GCC complains that the literal value overflows the type. So cast 
  explicitly.

* plugins.c: The cast and extra parens in this conditional do not appear to 
  be necessary.

* editor.c: event->x and event->y are gdouble, but 
  sci_get_position_from_xy() wants gints, so cast appropriately.

* socket.c: Moved the definition of socket_info here from socket.h.

* socket.h: Declare, don't define, the socket_info struct here. Some extra 
  footwork is needed here since the struct structure is being defined as 
  well.

* tm_workspace.c: Got rid of a stray semicolon.

* c.c: The cpp conditional should first check whether DEBUG_C is actually 
  defined or not, before using it in a conditional expression. This change
  gets rid of the warning, but what you might want to do instead is just 
  change the #if into an #ifdef. (I couldn't do that without knowing how 
  DEBUG_C is used, so I leave that to you.)

* sort.c: error() expects a formatted string + optional arguments, but 
  since we're just passing a single, variable string, GCC gets nervous 
  about not being able to check the format. Use a plain "%s" + string to 
  set it at ease.


The biggest portability issue, however, is one that a patch is not 
well-suited to fix: the use of C++-style comments in C code. GCC allows 
this, but will readily warn that "C++ style comments are not allowed in ISO 
C90", and Unix compilers almost universally choke on them as a syntax 
error.


--Daniel


-- 
NAME   = Daniel Richard G.       ##  Remember, skunks       _\|/_  meef?
EMAIL1 = skunk at iskunk.org        ##  don't smell bad---    (/o|o\) /
EMAIL2 = skunk at alum.mit.edu      ##  it's the people who   < (^),>
WWW    = http://www.******.org/  ##  annoy them that do!    /   \
--
(****** = site not yet online)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: geany-fixes.patch
Type: text/x-diff
Size: 45828 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/users/attachments/20080217/550d4046/attachment.patch>


More information about the Users mailing list