Closed Thread
Results 1 to 10 of 10

Thread: Struct in C and C++

  1. #1
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23

    Struct in C and C++

    Is struct in C and C++ the same?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Lop's Avatar
    Lop
    Lop is offline Speaks fluent binary
    Join Date
    May 2006
    Posts
    1,178
    Rep Power
    30
    Quote Originally Posted by dirkfirst
    Is struct in C and C++ the same?
    No they are not

  4. #3
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31
    Errm, you use them exactly the same way:

    C:

    typedef struct blabla
    {
    int x;
    char z;
    }

    c++:
    typedef struct blabla
    {
    int x;
    char z;
    }

  5. #4
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31
    Well, accually let me correct myself.
    In some compilers ( Turbo C for example ), all C struct operations and declares must begin with `struct`:

    Code:
    typedef struct MNT_DEV{
    byte oport;
    byte iport;
    };
    
    void main(void)
    {
    struct MNT_DEV mnt_pt;
    
    struct mnt_pt.iport = 0x02; /* Normally mnt_pt.iport = 0x02; would be all you need */
    
    }
    But other than that you use them the exact same way.

  6. #5
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    So they are the same or they are not? lol

  7. #6
    TkTech's Avatar
    TkTech is offline The Crazy One
    Join Date
    Jun 2006
    Location
    Canada
    Posts
    1,412
    Blog Entries
    1
    Rep Power
    31
    yes, the only differnce is that sometimes c compilers will require you put the keyword "struct" infront of all structure operations, ie:
    Code:
    struct header.i = 0; //Works
    header.i = 0; //Nope, no worky

  8. #7
    Kaabi Guest
    I'd always thought the structure was the same, and it appears I was right, although I didn't know about that "struct" thing.

  9. #8
    kia
    kia is offline Newbie
    Join Date
    Nov 2007
    Location
    in living in Sharjah (DUBAI) at the dormtory
    Posts
    24
    Rep Power
    0
    hi according to what i undrestand from the link jonh gave us there should a difference btw structs in C and c++


    structs don't copy in C. That is, if a and b are structs then the line a = b; doesn't work. Nor will structs be fed into functions as arguments. The only way to deal with them sensibly is to use pointers to them, or to write functions to copy their elements explicitly

    from :Differences between C and C++

  10. #9
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42
    Please don't bump years-old threads, kia!

  11. #10
    kia
    kia is offline Newbie
    Join Date
    Nov 2007
    Location
    in living in Sharjah (DUBAI) at the dormtory
    Posts
    24
    Rep Power
    0
    ok but tel me make things clear first i didnt do this by porpose if i choosed these topic it is because i m actualy taking some course in struct i mean we reach the chapter about struct so this why anyway sorry and i didnt know that i may get warnig for this so sory then for this mistake
    hope my sory ll be accepted
    Last edited by kia; 03-05-2008 at 03:30 AM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how to use struct referencing
    By codehunter22 in forum C and C++
    Replies: 2
    Last Post: 06-02-2011, 09:20 PM
  2. Array Struct Example
    By jclarke in forum C and C++
    Replies: 9
    Last Post: 04-23-2011, 02:00 AM
  3. [C] Use a struct in a fseek()
    By stefanostefano in forum C and C++
    Replies: 3
    Last Post: 10-17-2010, 10:05 PM
  4. [ask]pointer to struct
    By kiddies in forum C and C++
    Replies: 3
    Last Post: 12-07-2009, 06:53 PM
  5. Problem with struct
    By MichaelNQ in forum C and C++
    Replies: 0
    Last Post: 03-24-2009, 03:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts