cons int manipulation

Discussion in 'C Programming' started by rahulsinner@gmail.com, Apr 6, 2006.

  1. Guest

    Hi,

    Consider the following.

    #include <stdio.h>

    int main()
    {
    const int i=10;
    int *ptr=&i;
    *ptr=20;
    return 0;
    }

    This code compiles with a "suspicious pointer conversion" warning and
    thus, is able to voilate the integrity of constants.
    What does the standard say about it?

    Rahul
    , Apr 6, 2006
    #1
    1. Advertising

  2. Chris Dollin Guest

    wrote:

    > Hi,
    >
    > Consider the following.
    >
    > #include <stdio.h>
    >
    > int main()
    > {
    > const int i=10;
    > int *ptr=&i;
    > *ptr=20;
    > return 0;
    > }
    >
    > This code compiles with a "suspicious pointer conversion" warning and
    > thus, is able to voilate the integrity of constants.
    > What does the standard say about it?


    I expect it says that it's a constraint violation and that a diagnostic
    must be issued - which it was.

    Perhaps your compiler has knobs that will make warnings into don't-produce-
    object-code errors. Turn them up.

    --
    Chris "1680x1050" Dollin
    "Reaching out for mirrors hidden in the web."
    Chris Dollin, Apr 6, 2006
    #2
    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. Schnoffos
    Replies:
    2
    Views:
    1,211
    Martien Verbruggen
    Jun 27, 2003
  2. Hal Styli
    Replies:
    14
    Views:
    1,634
    Old Wolf
    Jan 20, 2004
  3. arun
    Replies:
    8
    Views:
    453
    Dave Thompson
    Jul 31, 2006
  4. aling
    Replies:
    8
    Views:
    947
    Jim Langston
    Oct 20, 2005
  5. static cons v/s cons

    , Dec 7, 2008, in forum: C Programming
    Replies:
    5
    Views:
    452
    James Kuyper
    Dec 8, 2008
Loading...

Share This Page