this is a "c" question

    Date: 12/22/04 (Algorithms)    Keywords: no keywords

    UpD: questions answered.
    thanks a bunch.

    #define false   (0)
    #define true    (!false)
    

    how simple the real truth is...

    well anyways...

    reading embedded c code makes me feel like an idiot...



    1.
    what does this do? i couldn't figure out if it's even legal
    unsigned char poop1 :   1;      // yes it a single colon and that's why it doesn't make sense to me...
    

    does it make a difference if there's a few hundred of those statements inside a struct {}?


    2. this i understand works.... there's no errors and this application works...
    but don't understand how

    i'll try to be as clear as possible.

    In one file there is a few macros like this...
    #define  POOP1    "A"
    #define  POOP2    "B"
    ...
    
    //then there is a table of strings
    static const char* const table_of_strings[MAX]=
    {
    POOP1"This will be a first string",                  //so in memory it just looks like 'AThis will be...'?
    POOP2"This will be a second string",
    ...
    };
    
    
    
    then there's a function that does something like this...
    
    const char* str = table_of_strings[i];
    set_poop(*str-'A');                     //exactly what happens here? pointer to str got subtracted with pointer of 'A'?? or else?
    
    
    and this is not even it.
    
    
    Then in another file.... it has this enumerator.
    
    typedef enum TAG
    {
     P_1,                    //aren't unspecified enums are just 0,1,2 ?
     P_2,
     ...
    } POOP_TAG;
    
    
    POOP_TAG current_poop;
    
    
    then that above mentioned function
    set_poop() receives poopie parameter from the first file and does the following...
    
    current_poop = poopie;
    
    

    so i wasn't sure how is it possible to it like this... i don't think i fully understand how macros work. (which i thought just replace the text they stand for)

    i'm not very sure if a single person can understand what i tried to explain here, thus i will try tomorrow again, since i don't have the exact code right in front of me...

    Source: http://www.livejournal.com/community/algorithms/41163.html

« Search for several substrings || network status monitor project »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home