Skip to content

Instantly share code, notes, and snippets.

@kalimatas
Last active August 29, 2015 14:14
Show Gist options
  • Save kalimatas/216cd609604993824e00 to your computer and use it in GitHub Desktop.
Save kalimatas/216cd609604993824e00 to your computer and use it in GitHub Desktop.
Struct size in C
#include <stdio.h>
#include <limits.h>
typedef struct _zval_struct zval;
typedef struct _zend_object {
int *ce;
int *properties;
zval **properties_table;
int *guards;
} zend_object;
struct tmp {
char *val;
int len;
};
typedef union _zvalue_value {
long lval;
double dval;
struct {
char *val;
int len;
} str;
int *ht;
zend_object obj;
} zvalue_value;
struct _zval_struct {
zvalue_value value;
unsigned int refcount__gc;
unsigned char type;
unsigned char is_ref__gc;
};
typedef struct _gc_root_buffer {
struct _gc_root_buffer *prev;
struct _gc_root_buffer *next;
unsigned int handle;
union {
zval *pz;
const int *handlers;
} u;
} gc_root_buffer;
typedef struct _zval_gc_info {
zval z;
union {
gc_root_buffer *buffered;
struct _zval_gc_info *next;
} u;
} zval_gc_info;
int main()
{
char *cptr;
int a = 3;
int *b = &a;
int **c = &b;
printf("Storage size for size_t : %lu \n", sizeof(size_t));
printf("Storage size for char ptr : %lu \n", sizeof(cptr));
printf("Storage size for **c : %lu \n", sizeof(c));
printf("Storage size for unsigned char : %lu \n", sizeof(unsigned char));
printf("Storage size for unsigned int : %lu \n", sizeof(unsigned int));
printf("Storage size for unsigned long : %lu \n", sizeof(unsigned long));
printf("Storage size for unsigned long long: %lu \n", sizeof(unsigned long long));
printf("Storage size for double : %lu \n", sizeof(double));
printf("\n");
zvalue_value myStruct;
printf("Storage size for struct zend_object : %lu \n", sizeof(zend_object));
printf("Storage size for struct tmp : %lu \n", sizeof(struct tmp));
printf("Storage size for union zvalue_value : %lu \n", sizeof(zvalue_value));
printf("Storage size for struct _zval_struct : %lu \n", sizeof(struct _zval_struct));
printf("Storage size for struct zval_gc_info : %lu \n", sizeof(zval_gc_info));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment