Thread: What is legal and what is illegal?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    91

    What is legal and what is illegal?

    Code:
    int i, *p, *q;
    
    // is this legal or illegal? Which one is legal and what is not?
    
    p = i;
    * p = &i;
    &p = q;
    p = &q;
    p = *&q;
    p =q;
    p = *q;
    *p = q;
    *p = *q;
    
    //Just wondering which of these are legal in all situations..

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok... that was lame.

    Code:
    p = i;
    * p = &i;
    &p = q;
    p = &q;
    p = *&q;
    p =q;
    p = *q;
    *p = q;
    *p = *q;

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Create a program, see which ones generate error messages, hence the answer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Hey... why you gotta pull the moderator card on me, Salem? I am sorry

Popular pages Recent additions subscribe to a feed