Re: a few doubts!



On Sat, 30 Apr 2005 10:18:43 -0400, in comp.lang.c , Lew Pitcher
<lpitcher@xxxxxxxxxxxx> wrote:

>> char * a= "bcd";

>the array of 4 char cannot be altered

yes

>> strcpy(a,"hello");

so this is undefined behaviour.

>The more knowledgable ones around here will tell you whether this is "illegal
>behaviour" (because of the side-effect of strcpy(), which would be to attempt
>to overwrite a char constant) or just "undefined behaviour".

It is undefined. There's no syntax error here, so no reason to abort
compilation, if thats what you mean by 'illegal'.

>> a[0] = 't';
>
>IIUC, this should be illegal.

Its undefined behaviour.

>The compiler is non-compliant?

the warning levels are too low?

>The compiler is broken?

The compiler is operating perfectly, but isn't obligated to produce a
diagnostic for careless programming.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.



Relevant Pages

  • Re: large files: when ubiquitous?
    ... >> The fact that undefined behaviour is invoked is an immediate consequence ... If your program complies with the rules of the C standard, ... branches are completely equivalent and both invoke undefined behaviour ... As with every transformation a compiler does, ...
    (comp.os.linux.development.system)
  • Re: large files: when ubiquitous?
    ... Your claim that undefined behaviour is invoked is demonstrably ... The C standard can speak till it's blue in the face - it won't unseat ... the logic of computability that rules here. ... as it is computed by the compiler. ...
    (comp.os.linux.development.system)
  • Re: operators similar to functions?
    ... The language specifies left-to-right associativity (or its ... undefined behaviour; however the compiler cannot know that. ... might avoid overflow but another order might not. ...
    (comp.lang.c)
  • Re: the standard is so strange
    ... Undefined behaviour. ... The order of evaluation of the function designator, ... but there is a sequence point before the actual call. ... there's no especial reason to expect that the same compiler won't make ...
    (comp.lang.c)
  • Re: How programming in C got me in trouble with the law
    ... Where the Standard specifies that the behaviour is ... running Spyware. ... If I had reason to believe that a compiler might start running ... spyware after encountering undefined behaviour I wouldn't ...
    (comp.lang.c)