Skip to content

Instantly share code, notes, and snippets.

@sambler
Created November 17, 2019 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sambler/c8d9e036723f96c16b9cf3d0877fe5ee to your computer and use it in GitHub Desktop.
Save sambler/c8d9e036723f96c16b9cf3d0877fe5ee to your computer and use it in GitHub Desktop.
check size and alignment of struct members
/*
* test alignments of struct members
* run on multiple platforms to compare output
cc test-blend-bGPDstroke.c -o testpad
./testpad
*/
#include <stdio.h>
#include <stddef.h>
// copied from DNA_gpencil_types.h e5b788bad8bc
struct bGPDspoint;
struct bGPDtriangle;
typedef struct bGPDstroke_Runtime {
/** runtime final colors (result of original colors and modifiers) */
float tmp_stroke_rgba[4];
/** runtime final fill colors (result of original colors and modifiers) */
float tmp_fill_rgba[4];
/** temporary layer name only used during copy/paste to put the stroke in the original layer */
char tmp_layerinfo[128];
/** Runtime falloff factor (only for transform). */
float multi_frame_falloff;
char _pad[4];
/** Original stroke (used to dereference evaluated data) */
struct bGPDstroke *gps_orig;
} bGPDstroke_Runtime;
typedef struct bGPDstroke {
struct bGPDstroke *next, *prev;
/** Array of data-points for stroke. */
struct bGPDspoint *points;
/** Tessellated triangles for GP Fill. */
struct bGPDtriangle *triangles;
/** Number of data-points in array. */
int totpoints;
/** Number of triangles in array. */
int tot_triangles;
/** Thickness of stroke. */
short thickness;
/** Various settings about this stroke. */
short flag, _pad[2];
/** Init time of stroke. */
double inittime;
/** Color name. */
char colorname[128];
/** Material index. */
int mat_nr;
/** Caps mode for each stroke extreme */
short caps[2];
/** gradient control along y for color */
float gradient_f;
/** factor xy of shape for dots gradients */
float gradient_s[2];
char _pad_3[4];
/** Vertex weight data. */
struct MDeformVert *dvert;
void *_pad3;
struct bGPDstroke_Runtime runtime;
} bGPDstroke;
int main(int argc, char ** argv)
{
printf("sizeof char - %lu\n",sizeof(char));
printf("sizeof short - %lu\n",sizeof(short));
printf("sizeof int - %lu\n",sizeof(int));
printf("sizeof long - %lu\n",sizeof(long));
printf("sizeof long long - %lu\n",sizeof(long long));
printf("sizeof float - %lu\n",sizeof(float));
printf("sizeof double - %lu\n",sizeof(double));
printf("sizeof long double - %lu\n",sizeof(long double));
printf("sizeof void* - %lu\n",sizeof(void*));
printf("sizeof size_t - %lu\n",sizeof(size_t));
printf("\nOffsets:\n");
printf("next=%ld;\n", (long) offsetof(bGPDstroke, next));
printf("prev=%ld;\n", (long) offsetof(bGPDstroke, prev));
printf("points=%ld;\n", (long) offsetof(bGPDstroke, points));
printf("triangles=%ld;\n", (long) offsetof(bGPDstroke, triangles));
printf("totpoints=%ld;\n", (long) offsetof(bGPDstroke, totpoints));
printf("tot_triangles=%ld;\n", (long) offsetof(bGPDstroke, tot_triangles));
printf("thickness=%ld;\n", (long) offsetof(bGPDstroke, thickness));
printf("flag=%ld;\n", (long) offsetof(bGPDstroke, flag));
printf("_pad=%ld;\n", (long) offsetof(bGPDstroke, _pad));
printf("inittime=%ld;\n", (long) offsetof(bGPDstroke, inittime));
printf("colorname=%ld;\n", (long) offsetof(bGPDstroke, colorname));
printf("mat_nr=%ld;\n", (long) offsetof(bGPDstroke, mat_nr));
printf("caps=%ld;\n", (long) offsetof(bGPDstroke, caps));
printf("gradient_f=%ld;\n", (long) offsetof(bGPDstroke, gradient_f));
printf("gradient_s=%ld;\n", (long) offsetof(bGPDstroke, gradient_s));
printf("_pad_3=%ld;\n", (long) offsetof(bGPDstroke, _pad_3));
printf("dvert=%ld;\n", (long) offsetof(bGPDstroke, dvert));
printf("_pad3=%ld;\n", (long) offsetof(bGPDstroke, _pad3));
printf("runtime=%ld;\n", (long) offsetof(bGPDstroke, runtime));
printf("sizeof(bGPDstroke)=%ld\n", (long) sizeof(bGPDstroke));
// exit cleanly if we get here
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment