Re: [xml] libxml2 API crazy?



On Mon, 2013-04-29 at 08:32 +0400, Nikita Churaev wrote:
It doesn't have anything to do with C standard.

It does. Take for example:

struct A {
  int q;
  int w;
  /* end of common part */

  float x;
};

struct B {
  int q;
  int w;
  /* end of common part */

  double x;
};

What if the C standard allows the compiler to place q and w further
apart in struct A than in struct B?

Then every kernel or device driver on the planet would break, as would
large amount of application code. But it doesn't allow the compiler that
freedom.

C specifies the behaviour very precisely and carefully exactly so you
can do this. See "structure padding"...

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]