cons int manipulation

R

rahulsinner

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
 
C

Chris Dollin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top