doubt in structures

This is a discussion on doubt in structures within the C Programming forums, part of the General Programming Boards category; I am having two structures with same elements. shall i give like this.. Code: struct emp { int accno; char ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    39

    doubt in structures

    I am having two structures with same elements. shall i give like this..

    Code:
    struct emp 
    {
       int accno;
       char name[10];
    };
    
    struct acc
    {
       int accno;
       char name[10];
    };
    
    struct emp e=struct acc a;
    Just we already given values for emp structure. shall i assign it like this...

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    No, if you have two different names for structures that contain the same thing, the compiler will still say those are different structs - you can't copy structs of different names from one to another.

    What is the reason you have two structs with the same content and different names in the first place? It makes no sense.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Oh how cute, two little structs that look like identical twins.
    Sarcasm aside, that assignment statement will not even compile.

    Now could you please do us a favour and erase the word "doubt" from your vocabulary and start using the word "question" instead? Sadly many people particularly of indian origin, gets this wrong. Questions also end in a question mark "?"
    Last edited by iMalc; 04-25-2008 at 03:49 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    C is known for its lack of type safety, but be that as it may, its not quite that oblivious to types.

    I have said it before, and I will say it again, a compiler isn't the sage of programming knowledge that many will lead you to believe. How should it know that you developed two identical structures with only a difference in names? You can technically get around this with type casting, but the reason behind this should be obvious.

    Code:
    struct x { int y, z; };
    struct a { int b, c; };
    struct t  { int u; double v; };
    
    struct x var1;
    struct a var2;
    struct t var3;
    
    // If I can do this.....
    var1 = var2;
    
    // What stops me from doing this?
    var3 = var2;
    In C++ I actually see application for what you are trying to do. It is one way to bypass encapsulation... but even that is not a common practice.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Cool it with the racial overtones, iMalc. Though there is a lot of validity in your statement, I see doubt misused by more than one ethnicity on the net. Incidentally, even better than putting such irritating words such as "question" in your title. Why not call a thread something useful and more flame retardant such as "I don't grasp structs" or "struct conversion won't compile"

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Cool it with the racial overtones, iMalc.
    Don't even go there man, you couldn't be furthur from the truth. My best friend through university was from India.
    I agree with the advice you've given.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Quote Originally Posted by iMalc View Post
    Now could you please do us a favour and erase the word "doubt" from your vocabulary and start using the word "question" instead? Sadly many people particularly of indian origin, gets this wrong. Questions also end in a question mark "?"
    They get it wrong because there is a very popular English translation dictionary which has the wrong translation. Seriously, I'm not kidding. Please, give them a break.

    EDIT: There is a similar error in a popular English/Chinese dictionary as well.

    I didn't really think your comment was racist, but it's uninformed. There is indeed a correlation between Indian and getting this word wrong, but the reason for the correlation is the dictionary itself. Until the dictionaries are fixed I'm reserving my blame for the dictionary editors.
    Last edited by brewbuck; 04-25-2008 at 03:38 PM.

  8. #8
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Perhaps its not so much as an incorrect translation so much as its a context specific translation:

    I question his abilities. = I doubt his abilities.
    I have a question about the assignment. != I have a doubt about the assignment.

    But man is the second one ambiguous... Either way, I am not calling anyone a racist. I just hate to see some people take things the wrong way and in the process lose credibility in someone very credible.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Okay sorry man, we're cool.
    As it happens I've been sick off work lately with a cold and got lots of headaches. Probably a few people noticed my poorer attitude recently. Sorry all.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Yeah its cool man. We all get like that sometimes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-09-2009, 11:06 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  4. Doubt -- Structures
    By bmsar in forum C Programming
    Replies: 0
    Last Post: 12-25-2002, 10:55 PM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM

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