cons int manipulation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rahulsinner@gmail.com

    #1

    cons int manipulation

    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

  • Chris Dollin

    #2
    Re: cons int manipulation

    rahulsinner@gma il.com wrote:
    [color=blue]
    > 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?[/color]

    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."

    Comment

    Working...