to record my stupid mistake in programming

This post is used to record one mistake while my coding – just for my bad memory:) I have to admit that it spent me the whole day to figure out what was wrong, as it looked prefect except parse error during compiling. At least 2 things are revealed: 1, I suck on C; 2, I need to learn compiler theory…

#include <stdio.h>
#include <stdlib.h>

typedef struct _Big{
 char big;
 int bigInt;

typedef struct _Bigger{
 char bigger;
 Big *bigP;

typedef struct _Biggest{
 char biggest;
 Bigger *biggerP;

#define GET_BIG( _biggestP) 

#define BIGINT_IS_ONE( _biggestP, _bigInt) 
 ( 1 == GET_BIG( _biggestP)->(_bigInt))
 // daveti: insane happens here, like 'xxx->(xxx)'

int main(void)
 Biggest *bP = calloc( 1, sizeof( Biggest));
 bP->biggerP = calloc( 1, sizeof( Bigger));
 bP->biggerP->bigP = calloc( 1, sizeof( Big));

 bP->biggerP->bigP->bigInt = 2;
 printf( "i = %sn"
 ,( BIGINT_IS_ONE( bP, bigInt) ? "one" : "not one")

 return 0;

About daveti

Interested in kernel hacking, compilers, machine learning and guitars.
This entry was posted in Programming and tagged . Bookmark the permalink.

1 Response to to record my stupid mistake in programming

  1. sex dating says:

    Another great website about this product you can find over here sex!!! Let me know what you think about this site and i’ll subscribe to your blog!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.