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

Re: [libvirt] alignment of data fields when compiling with mingwin

2010/10/15  <arnaud champion devatom fr>:
> Hi,
> I'm currently working on libvirt csharp bindings, and I have some trouble
> with virConnectOpenAuth marshaling.
> I need to know what is the alignment of data fields in structure when
> compiling with mingwin.
> Anyone know that ?
> cheers,
> Arnaud Champion

Why do you need to know the alignment? Do you need to build or access
members of the virConnectCredential or virConnectAuth structs by
offset in memory?

The Wikipedia article about data structure alignment might be helpful
when you really need to care about alignment.

If you actually need the offset of the members in those structs you
can just use the offsetof macro and let the compiler tell you:

#include <stdio.h>
#include <stddef.h>
#include <libvirt/libvirt.h>

void main(void)
    printf("  type      %2u\n", offsetof(virConnectCredential, type));
    printf("  prompt    %2u\n", offsetof(virConnectCredential, prompt));
    printf("  challenge %2u\n", offsetof(virConnectCredential, challenge));
    printf("  defresult %2u\n", offsetof(virConnectCredential, defresult));
    printf("  result    %2u\n", offsetof(virConnectCredential, result));
    printf("  resultlen %2u\n", offsetof(virConnectCredential, resultlen));
    printf("  credtype  %2u\n", offsetof(virConnectAuth, credtype));
    printf("  ncredtype %2u\n", offsetof(virConnectAuth, ncredtype));
    printf("  cb        %2u\n", offsetof(virConnectAuth, cb));
    printf("  cbdata    %2u\n", offsetof(virConnectAuth, cbdata));

Output on x86:

  type       0
  prompt     4
  challenge  8
  defresult 12
  result    16
  resultlen 20

  credtype   0
  ncredtype  4
  cb         8
  cbdata    12

Output on x86_64:

  type       0
  prompt     8
  challenge 16
  defresult 24
  result    32
  resultlen 40

  credtype   0
  ncredtype  8
  cb        16
  cbdata    24

[1] http://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86


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