By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

compile's problem?

P: n/a
mos
Hi! the following code will run without any error on the VC7.1 stdio
debug mode. who can tell me what's the problem?

struct st
{
int a;
};
int _tmain(int argc, _TCHAR* argv[])
{
st* p = new st;
delete p;
p->a = 0;
return 0;
}

mos.
Aug 6 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Aug 6, 7:11 pm, "mos" <mmosqu...@163.comwrote:
Hi! the following code will run without any error on the VC7.1 stdio
debug mode. who can tell me what's the problem?

struct st
{
int a;};

int _tmain(int argc, _TCHAR* argv[])
Non-standard.
{
st* p = new st;
delete p;
p->a = 0;
Undefined behavior.
return 0;
Not necessary.
>
}

mos.
-N

Aug 6 '07 #2

P: n/a
mos wrote:
Hi! the following code will run without any error on the VC7.1 stdio
debug mode. who can tell me what's the problem?

struct st
{
int a;
};
int _tmain(int argc, _TCHAR* argv[])
{
st* p = new st;
delete p;
p->a = 0;
return 0;
}
I'm not really sure what your question is. I assume you know that the
program invokes undefined behaviour. Had you been expecting a
compile-time diagnostic? It is not required.
Aug 6 '07 #3

P: n/a
Neelesh Bodas wrote:
On Aug 6, 7:11 pm, "mos" <mmosqu...@163.comwrote:
Hi! the following code will run without any error on the VC7.1
return 0;
Not necessary.
In spite of the fact that a specific return is not required from
main(), it is not wrong to do so and in my opinion is better code. That
indicates that the programmer did not merely forget it. It certainly
doesn't require "correction" in a newsgroup.


Brian
Aug 6 '07 #4

P: n/a
mos wrote:
Hi! the following code will run without any error on the VC7.1 stdio
debug mode. who can tell me what's the problem?

struct st
{
int a;
};
int _tmain(int argc, _TCHAR* argv[])
{
st* p = new st;
delete p;
p->a = 0;
return 0;
}

mos.
One of the insidious forms of undefined behavior is it working
error free (at least for a short time).
Aug 7 '07 #5

P: n/a
On Aug 7, 1:10 pm, Ron Natalie <r...@spamcop.netwrote:
mos wrote:
Hi! the following code will run without any error on the VC7.1 stdio
debug mode. who can tell me what's the problem?
struct st
{
int a;
};
int _tmain(int argc, _TCHAR* argv[])
{
st* p = new st;
delete p;
p->a = 0;
return 0;
}
One of the insidious forms of undefined behavior is it working
error free (at least for a short time).
The most frequent result of using undefined behavior seems to be
that the code works perfectly in all of the tests, but then
fails in a very visible fashion during the demo in front of the
important client.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Aug 7 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.