Urgent question

Posted on 2005-04-26
Last Modified: 2010-04-15
i defined the type of a node for a search tree like this:

typedef struct tSearchTree{
        char* s;
        struct tSearchTree* children[MAXCHILDREN];

Can i have some kind of macro which makes me access to the children like below, without change the above typedef:
node->left; or node->right;

I tried this macros:
#define ->left ->children[0];
#define ->right ->children[1];

but naturally didn't work.

Any idea?
Question by:RomanRega
    LVL 45

    Accepted Solution

    Hi RomanRega,

    How about
    #define  left children[0]
    #define right children[1]

    if you have variables named left or right within the functions, then I dont see a way to do what you are asking for and you will have to change the typedef

    LVL 3

    Author Comment

    Jeez the answer is that simple. :)

    Im almost ashamed.

    Thanks :)
    LVL 1

    Expert Comment

    Perhaps you should remove the ->, but I'm not sure what you ask is possible with a macro.
    You could define a struct like this:

    typedef struct tSearchTree2{
            int left;
            int right;

    typedef struct tSearchTree2{
            char* s;
            struct tSearchTree2* children[MAXCHILDREN];

    and then do a memcpy from the original, tSearchTree to tSearchTree2. Then you can access the copy, and once you're finished, copy it back.

    LVL 45

    Expert Comment

    > you will have to change the typedef
    or the variable names ...

    I would recommend changing typedef to left and right so that it is logocally clearer and easier to maintain. But from your question title, it seems that you do not have much time left to accomodate such changes, so #define and changing local variable names might be the way to go.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    port mapped I/o query 10 111
    FILE closing 11 64
    why "." vs "->" 23 112
    C Language combined operators 28 97
    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now