Error in the documentation

Hello everyone,

I’m in the process of creating a GTK 4 language binding for PureBasic and for that I need to re-define constants, bitfields and structures then write an Import for all functions.

According to the documentation Gtk.Border the structure is incorrectly defined like this :

struct GtkBorder {
  gint16 left;
  gint16 right;
  gint16 top;
  gint16 bottom;
}

A simple C code to prove it :

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib.h>

typedef struct _GtkBorder2
{
  gint16 left;
  gint16 right;
  gint16 top;
  gint16 bottom;
} GtkBorder2;

typedef struct _GtkBorder3
{
  gint32 left;
  gint32 right;
  gint32 top;
  gint32 bottom;
} GtkBorder3;

int main (int argc, char *argv[])
{

    printf("GtkBorder : %zu\n", sizeof(GtkBorder));
    printf("GtkBorder2 : %zu\n", sizeof(GtkBorder2));
    printf("GtkBorder3 : %zu\n", sizeof(GtkBorder3));

    return 0;
}

The code above print :

GtkBorder : 16
GtkBorder2 : 8
GtkBorder3 : 16

I think the same error appear in the GTK 3 documentation as well.

Best regards

I am not able to reproduce on my system, gcc machine triple is x86_64-linux-gnu:

GtkBorder : 8
GtkBorder2 : 8
GtkBorder3 : 16

You could check the source code, which is linked from the documentation:

/**
 * GtkBorder:
 * @left: The width of the left border
 * @right: The width of the right border
 * @top: The width of the top border
 * @bottom: The width of the bottom border
 *
 * A struct that specifies a border around a rectangular area.
 *
 * Each side can have different width.
 */
struct _GtkBorder
{
  gint16 left;
  gint16 right;
  gint16 top;
  gint16 bottom;
};

The problem is that you’re doing sizeof(GtkBorder), but you really can’t assume that the C compiler will just sum up the size of all the fields. C compilers are allowed to pad and align structured data as they see fit.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.