compile's problem?

M

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

Alf P. Steinbach

* mos:
Hi! the following code will run without any error on the VC7.1 stdio
debug mode.

I doubt it.

who can tell me what's the problem?

struct st
{
int a;
};
int _tmain(int argc, _TCHAR* argv[])

Non-standard startup function. With the code you have presented it
shouldn't even compile with VC. Use standard C++ 'main'.

{
st* p = new st;
delete p;
p->a = 0;

Undefined behavior.
 
N

Neelesh Bodas

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
 
E

Eberhard Schefold

mos said:
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.
 
D

Default User

Neelesh said:
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
 
R

Ron Natalie

mos said:
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).
 
J

James Kanze

mos said:
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.
 

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
474,290
Messages
2,571,453
Members
48,129
Latest member
DianneCarn

Latest Threads

Top