enum stuff get lost

Discussion in 'C Programming' started by ajay, Jun 24, 2003.

  1. ajay

    ajay Guest

    Hi All,
    I get lost in enum stuff.
    can anyone help me out from this puzzle.
    i'm not able to get the values which i set.
    see the following piece of code.


    /** typedef.h ****/

    /***** I have an enum ******/

    enum RequestParameter{
    request_IMSI = 0,
    request_AuthenticationSet = 1,
    request_SubscriberData = 2,
    request_CUG_Information = 3,
    request_Ki = 4
    };

    /*** now i have to create an arry of above enum of size 2 ******/
    typedef RequestParameter RequestParameters[2];


    /**** getSet.c ******/

    /*** I wrote method to get and set this enum array ***/
    RequestParameters reqParams;

    void setReqParams(RequestParameters* in)
    {
    reqParams = in;
    }

    bool getReqParams(RequestParameters* out)
    {
    out = reqParams;
    }

    /**** main.c *****/
    /***** now i use get set methods *****/

    /*** here i set the value ***/

    RequestParameters reqParams;
    reqParams[0] = request_IMSI;
    setReqParams(&reqParams);


    /**** here i get the value ******/
    RequestParameters reqParams;
    getReqParams(&reqParams));

    printf("reqParam = %d" , reqParam[0] );
    /** i'm not able to get the values which i set printed value is garbage ***/

    if ( reqParams[0] == request_IMSI )
    {
    ......
    }
    else if ( reqParams[0] == request_AuthenticationSet )
    {
    .....
    }

    ......
    ...
     
    ajay, Jun 24, 2003
    #1
    1. Advertisements

  2. Should be

    typedef enum RequestParameter RequestParameters[2];

    but typedefing arrays is rarely useful.
    'RequestParameters' is an array type that decays in a pointer type because it
    is a parameter. Are you sure you want a pointer to a pointer here?
    What is reqParams ?
    out = reqParams;

    What is reqParams ?
    Modifying a parameter is often the sign of a design error. Do you really want
    to do that?
    You can't do that outside a function.
    It's hard to understand the purpose of this function.
    It's hard to understand the purpose of this function.
    You seem completely confused. I think you should try to explain what you want
    to do exactly, and we will try to help you to implement it if it makes sense.
     
    Emmanuel Delahaye, Jun 24, 2003
    #2
    1. Advertisements

  3. ajay

    ajay Guest

    Tx ED for ur time.I solved it anyhow.

     
    ajay, Jun 25, 2003
    #3
  4. Groovy hepcat Emmanuel Delahaye was jivin' on 24 Jun 2003 15:13:05 GMT
    in comp.lang.c.
    Re: enum stuff get lost's a cool scene! Dig it!
    ^^^^^^^^^
    This is reqParams.
    ^
    RequestParams is not a parameter. RequestParams is, as you have
    correctly said, an array type. But the parameter, named in, is a
    pointer to this array type.
    See above.
    See above.
    I believe he's trying to modify what the parameter points at. Of
    course, he can't do that, since it is an array.

    --

    Dig the even newer still, yet more improved, sig!

    http://alphalink.com.au/~phaywood/
    "Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
    I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
     
    Peter Shaggy Haywood, Jun 27, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.