Operand function??

This is a discussion on Operand function?? within the C++ Programming forums, part of the General Programming Boards category; I am new to C, C++ programming. I do have 3 years of heavy VB experience and here is my ...

  1. #1
    Unregistered
    Guest

    Question Operand function??

    I am new to C, C++ programming. I do have 3 years of heavy VB experience and here is my problem:

    I am converting a C program to VB and I am almost done, but I do not understand what the following line of code in the original C program is doing. Here it is:

    Code:
    errflag->dir = 1;
    The part I do not understand is the operand symbols, ->

    errflag minus greater than dir = 1

    Can anyone clear the fog??

    Thanks for any info.

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    The -> is used when accessing a member of a structure through a pointer(at least it is in C, I suppose it could be something different in C++)

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Code:
    errflag->dir = 1;
    The above is a shorthand for saying this
    Code:
    (*errflag).dir = 1;
    And the '->' syntax is used in boh C and C++ for the same reason.

  4. #4
    Unregistered
    Guest
    That's it!!!

    Thank you so much for your expertise.

    I did not see this code at the top of the program:

    Code:
    struct n_d_flags        
    {
    	int dir;
    	int numtaps;
    	int rerr;
    };


    Code:
    errflag->dir = 1;
    Is this expression saying:

    If errflag then set the variable dir in the structure n_d_flags to 1?

    Thanks again.

  5. #5
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Is this expression saying:

    If errflag then set the variable dir in the structure n_d_flags to 1?
    It's not saying if anything!!

    It's directly assigning 1 to the member variable 'dir' in the object/structure 'errflag'.

  6. #6
    Unregistered
    Guest
    DOH!

    I see. I understand 100% now.

    It is simply assigning a 1 to dir in the structure n_d_flags.

    Thanks so much for your help.

    I have it working in my VB app now.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21