Re: Help me wrap PahoMQTT

new topic     » goto parent     » topic index » view thread      » older message » newer message

What I do to get structure alignments reliably, is construct simple C programs to output everything for me.

Makefile

CFLAGS = -Ieclipse/paho.mqtt.c/src 
 
all : test64.exe test32.exe 
    @test64.exe 
    @echo. 
    @test32.exe 
 
test64.exe : test.c 
    gcc -m64 -DBITS=64 -o $@ $< $(CFLAGS) 
 
test32.exe : test.c 
    gcc -m32 -DBITS=32 -o $@ $< $(CFLAGS) 

test.c

#include <stdio.h> 
#include <stddef.h> 
 
#include "MQTTClient.h" 
 
#if ( BITS == 64 ) 
#define ARCH_TYPE() printf( "-- 64-bit ------------------------------------\n" ) 
#else 
#define ARCH_TYPE() printf( "-- 32-bit ------------------------------------\n" ) 
#endif 
 
#define OFFSETOF( st, mb ) printf( "%-40s = %2d,\n", #st "__" #mb, offsetof(st,mb) ) 
#define SIZEOF( st ) printf( "SIZEOF_%-33s = %2d,\n", #st, sizeof(st) ) 
 
int main( int argc, char* argv[] ) 
{ 
    ARCH_TYPE(); 
     
    OFFSETOF( MQTTClient_willOptions, struct_id ); 
    OFFSETOF( MQTTClient_willOptions, struct_version ); 
    OFFSETOF( MQTTClient_willOptions, topicName ); 
    OFFSETOF( MQTTClient_willOptions, message ); 
    OFFSETOF( MQTTClient_willOptions, retained ); 
    OFFSETOF( MQTTClient_willOptions, qos ); 
    OFFSETOF( MQTTClient_willOptions, payload.len ); 
    OFFSETOF( MQTTClient_willOptions, payload.data ); 
    SIZEOF( MQTTClient_willOptions ); 
     
    return 0; 
} 

Output

C:\>mingw32-make 
-- 64-bit ------------------------------------ 
MQTTClient_willOptions__struct_id        =  0, 
MQTTClient_willOptions__struct_version   =  4, 
MQTTClient_willOptions__topicName        =  8, 
MQTTClient_willOptions__message          = 16, 
MQTTClient_willOptions__retained         = 24, 
MQTTClient_willOptions__qos              = 28, 
MQTTClient_willOptions__payload.len      = 32, 
MQTTClient_willOptions__payload.data     = 40, 
SIZEOF_MQTTClient_willOptions            = 48, 
 
-- 32-bit ------------------------------------ 
MQTTClient_willOptions__struct_id        =  0, 
MQTTClient_willOptions__struct_version   =  4, 
MQTTClient_willOptions__topicName        =  8, 
MQTTClient_willOptions__message          = 12, 
MQTTClient_willOptions__retained         = 16, 
MQTTClient_willOptions__qos              = 20, 
MQTTClient_willOptions__payload.len      = 24, 
MQTTClient_willOptions__payload.data     = 28, 
SIZEOF_MQTTClient_willOptions            = 32, 

Now I can copy/paste that output and format in my wrapper as I showed above.

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu