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. Advertising

  2. In 'comp.lang.c', (ajay) wrote:

    > 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];


    Should be

    typedef enum RequestParameter RequestParameters[2];

    but typedefing arrays is rarely useful.

    > /**** getSet.c ******/
    >
    > /*** I wrote method to get and set this enum array ***/
    > RequestParameters reqParams;
    >
    > void setReqParams(RequestParameters* in)


    '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?

    > {
    > reqParams = in;


    What is reqParams ?

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


    out = reqParams;

    What is reqParams ?
    Modifying a parameter is often the sign of a design error. Do you really want
    to do that?

    > }
    >
    > /**** main.c *****/
    > /***** now i use get set methods *****/
    >
    > /*** here i set the value ***/
    >
    > RequestParameters reqParams;
    > reqParams[0] = request_IMSI;


    You can't do that outside a function.

    > setReqParams(&reqParams);


    It's hard to understand the purpose of this function.

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


    It's hard to understand the purpose of this function.

    > 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 )
    > {
    > ....
    > }


    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.

    --
    -ed- [remove YOURBRA before answering me]
    The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    C-library: http://www.dinkumware.com/htm_cl/index.html
    FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
     
    Emmanuel Delahaye, Jun 24, 2003
    #2
    1. Advertising

  3. ajay

    ajay Guest

    Tx ED for ur time.I solved it anyhow.

    Emmanuel Delahaye <> wrote in message news:<Xns93A4AFA2E38BChsnoservernet@130.133.1.4>...
    > In 'comp.lang.c', (ajay) wrote:
    >
    > > 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];

    >
    > Should be
    >
    > typedef enum RequestParameter RequestParameters[2];
    >
    > but typedefing arrays is rarely useful.
    >
    > > /**** getSet.c ******/
    > >
    > > /*** I wrote method to get and set this enum array ***/
    > > RequestParameters reqParams;
    > >
    > > void setReqParams(RequestParameters* in)

    >
    > '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?
    >
    > > {
    > > reqParams = in;

    >
    > What is reqParams ?
    >
    > > }
    > >
    > > bool getReqParams(RequestParameters* out)
    > > {
    > > out = reqParams;

    >
    > out = reqParams;
    >
    > What is reqParams ?
    > Modifying a parameter is often the sign of a design error. Do you really want
    > to do that?
    >
    > > }
    > >
    > > /**** main.c *****/
    > > /***** now i use get set methods *****/
    > >
    > > /*** here i set the value ***/
    > >
    > > RequestParameters reqParams;
    > > reqParams[0] = request_IMSI;

    >
    > You can't do that outside a function.
    >
    > > setReqParams(&reqParams);

    >
    > It's hard to understand the purpose of this function.
    >
    > >
    > > /**** here i get the value ******/
    > > RequestParameters reqParams;
    > > getReqParams(&reqParams));

    >
    > It's hard to understand the purpose of this function.
    >
    > > 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 )
    > > {
    > > ....
    > > }

    >
    > 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.
     
    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!

    >In 'comp.lang.c', (ajay) wrote:
    >
    >> 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];

    >
    >Should be
    >
    >typedef enum RequestParameter RequestParameters[2];
    >
    >but typedefing arrays is rarely useful.
    >
    >> /**** getSet.c ******/
    >>
    >> /*** I wrote method to get and set this enum array ***/
    >> RequestParameters reqParams;

    ^^^^^^^^^
    This is reqParams.

    >> void setReqParams(RequestParameters* in)

    ^

    >'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?


    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.

    >> {
    >> reqParams = in;

    >
    >What is reqParams ?


    See above.

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

    >
    >What is reqParams ?


    See above.

    >Modifying a parameter is often the sign of a design error. Do you really want
    >to do that?


    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    549
  2. Jerminia
    Replies:
    3
    Views:
    633
    Roedy Green
    Oct 7, 2005
  3. Ernst Murnleitner

    How to enum an enum?

    Ernst Murnleitner, Nov 12, 2003, in forum: C++
    Replies:
    5
    Views:
    472
    Rolf Magnus
    Nov 13, 2003
  4. mrhicks
    Replies:
    2
    Views:
    428
    Dave Thompson
    Jun 10, 2004
  5. Alexander Adam

    Lost in encoding stuff

    Alexander Adam, Jan 16, 2008, in forum: C++
    Replies:
    3
    Views:
    354
    James Kanze
    Jan 17, 2008
Loading...

Share This Page