comparison tools/mb_c_source.m4 @ 213:a0a3196b1a05

Refactory pointer computation into a macro. - It is hard to read a complicate pointer calculation. A macro can make it more easy to be read.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 12 Dec 2008 09:35:27 +0800
parents 5f144bab5de1
children 104d83378582
comparison
equal deleted inserted replaced
212:5f144bab5de1 213:a0a3196b1a05
353 $2[ 353 $2[
354 }; 354 };
355 355
356 #ifndef MB_LSYM_GET_OBJ_WITH_NAME 356 #ifndef MB_LSYM_GET_OBJ_WITH_NAME
357 #define MB_LSYM_GET_OBJ_WITH_NAME 357 #define MB_LSYM_GET_OBJ_WITH_NAME
358
359 #define MB_SPRITE_OFF_2_PTR(x, off) (((void *)(x)) + (off))
360
358 static 361 static
359 mb_obj_t *mb_lsym_get_obj_with_name(mb_sprite_lsym_t *lsym, const char *sym) { 362 mb_obj_t *mb_lsym_get_obj_with_name(mb_sprite_lsym_t *lsym, const char *sym) {
360 int i; 363 int i;
361 364
362 for(i = 0; i < lsym->num_entries; i++) { 365 for(i = 0; i < lsym->num_entries; i++) {
363 if(strcmp(lsym->entries[i].sym, sym) != 0) 366 if(strcmp(lsym->entries[i].sym, sym) != 0)
364 continue; 367 continue;
365 return (mb_obj_t *)*((int*)(((void *)lsym) + lsym->entries[i].offset)); 368 return *(mb_obj_t **)MB_SPRITE_OFF_2_PTR(lsym,
369 lsym->entries[i].offset);
366 } 370 }
367 return NULL; 371 return NULL;
368 } 372 }
369 #endif /* MB_LSYM_GET_OBJ_WITH_NAME */ 373 #endif /* MB_LSYM_GET_OBJ_WITH_NAME */
370 374