Anyone knows what can be cause of this problem?
////////////////////////////////////////////////////////////
typedef struct _date_struct {
int date,month,year ;
}date_struct;
Class Date {
private :
date_struct m_data;
public :
Date& operator=(const Date& );
//.. Other stuff
};
Date::~Date()
{
FreeStruct(&m_d ata);
}
Date& Date::operator = (const Date& SrcDate)
{
FreeStruct(&m_D ata);
///...
return * this;
}
void Date::FreeStruc t(Date& lpData) //<- here is the problem.
{
memset(lpData,0 ,sizeof(Date));
return;
}
/////////////////////////////////////////////////////
My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn't happen
every I run the program. Anyone can tell me where this value from ? Is
there something wrong in my code? 11 2065
Aing wrote: Anyone knows what can be cause of this problem?
//////////////////////////////////////////////////////////// typedef struct _date_struct { int date,month,year ; }date_struct;
Class Date { private : date_struct m_data; public : Date& operator=(const Date& ); //.. Other stuff };
Date::~Date() { FreeStruct(&m_d ata); } Date& Date::operator = (const Date& SrcDate) { FreeStruct(&m_D ata); ///... return * this; }
void Date::FreeStruc t(Date& lpData) //<- here is the problem. { memset(lpData,0 ,sizeof(Date)); return; } /////////////////////////////////////////////////////
Since FreeStruct is a member function of Date, there is no need to
pass it something it can access anyway. There is also no
need to call FreeStruct from the destructor, since the object
is going to be deleted anyway. But this is not related to your problem.
My application crashed because lpData was set to 0x0000014 or some address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code.
What you see are just the symptoms. Watch out for array overflows, dangling
pointers etc.
--
Karl Heinz Buchegger kb******@gascad .at
"Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message news:40******** *******@gascad. at... > My application crashed because lpData was set to 0x0000014 or some address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion.
FreeStruct takes a Date but it is passed the date_struct*. Even if he
somehow manages to bash it to compile with a cast, he's still memsetting
using the size of the containing object (Date). Depending on what "other stuff"
is in the class that he omitted form the listing, the results could be catastrophic.
Ron Natalie wrote: "Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message news:40******** *******@gascad. at...
My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion. FreeStruct takes a Date but it is passed the date_struct*. Even if he somehow manages to bash it to compile with a cast, he's still memsetting using the size of the containing object (Date). Depending on what "other stuff" is in the class that he omitted form the listing, the results could be catastrophic.
Even if he was memsetting Date he's likely to get into problems. The
idiom of initializing by memsetting C type structures seems to a MS
thing, which doesn't work with C++ structs and classes where you are
likely to zap the vtable pointer.
Ron Natalie wrote: "Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message news:40******** *******@gascad. at... > My application crashed because lpData was set to 0x0000014 or some address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code? Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion. FreeStruct takes a Date but it is passed the date_struct*.
I blamed this to not posting the actual source code but instead retyping
it in the newsreader.
Even if he somehow manages to bash it to compile with a cast, he's still memsetting using the size of the containing object (Date). Depending on what "other stuff" is in the class that he omitted form the listing, the results could be catastrophic.
--
Karl Heinz Buchegger kb******@gascad .at
lilburne wrote: Ron Natalie wrote: "Karl Heinz Buchegger" <kb******@gasca d.at> wrote in message news:40******** *******@gascad. at...
>My application crashed because lpData was set to 0x0000014 or some
address around here. (I saw from DrWatSon log) But it doesn't happen every I run the program. Anyone can tell me where this value from ? Is there something wrong in my code?
Definitly. But the problem is located somewhere else in your code. What you see are just the symptoms. Watch out for array overflows, dangling pointers etc.
There seems to be some confusion. FreeStruct takes a Date but it is passed the date_struct*. Even if he somehow manages to bash it to compile with a cast, he's still memsetting using the size of the containing object (Date). Depending on what "other stuff" is in the class that he omitted form the listing, the results could be catastrophic.
Even if he was memsetting Date he's likely to get into problems. The idiom of initializing by memsetting C type structures seems to a MS thing, which doesn't work with C++ structs and classes where you are likely to zap the vtable pointer.
true.
But the OP used a POD struct.
memsetting to 0 should not be a problem in this case.
--
Karl Heinz Buchegger kb******@gascad .at
>>>> Ron Natalie writes:
Ron> There seems to be some confusion. FreeStruct takes a Date
Ron> but it is passed the date_struct*. Even if he somehow
Ron> manages to bash it to compile with a cast, he's still
Ron> memsetting using the size of the containing object (Date).
Ron> Depending on what "other stuff" is in the class that he
Ron> omitted form the listing, the results could be catastrophic.
Even if m_data represented a Date object, he's passing a reference to
the address of that object. Seems like he would get a compile error
since the func expects (Date& lpData).
Also memset requires the address and would need to be
memset(&lpData, 0,sizeof(Date)) ;
since a reference is passed in.
Date::~Date()
{
FreeStruct(&m_d ata);
}
Date& Date::operator = (const Date& SrcDate)
{
FreeStruct(&m_D ata);
///...
return * this;
}
void Date::FreeStruc t(Date& lpData) //<- here is the problem.
{
memset(lpData,0 ,sizeof(Date));
return;
}
Aing wrote: Anyone knows what can be cause of this problem?
For starters, try posting real code. The code that you posted doesn't
even compile, since you are trying to pass a 'Date*' argument as 'Date&'
parameter.
--
Best regards,
Andrey Tarasevich
Karl Heinz Buchegger wrote: ... Even if he was memsetting Date he's likely to get into problems. The idiom of initializing by memsetting C type structures seems to a MS thing, which doesn't work with C++ structs and classes where you are likely to zap the vtable pointer.
true. But the OP used a POD struct. memsetting to 0 should not be a problem in this case. ...
No, it is still a problem. You must be thinking about 'memcpy', not
about 'memset'. Strictly speaking, 'memset' cannot be used to
zero-initialize 'int' objects. And 'int' objects is exactly what the OP
is storing in his/her POD struct called 'date_struct'.
--
Best regards,
Andrey Tarasevich
Andrey Tarasevich wrote in news:10******** *****@news.supe rnews.com: Karl Heinz Buchegger wrote: ... Even if he was memsetting Date he's likely to get into problems. The idiom of initializing by memsetting C type structures seems to a MS thing, which doesn't work with C++ structs and classes where you are likely to zap the vtable pointer.
true. But the OP used a POD struct. memsetting to 0 should not be a problem in this case. ...
No, it is still a problem. You must be thinking about 'memcpy', not about 'memset'. Strictly speaking, 'memset' cannot be used to zero-initialize 'int' objects. And 'int' objects is exactly what the OP is storing in his/her POD struct called 'date_struct'.
I was under the impression that all C++ signed types have 1 of
3 formats 2s-compliment, 1s-compliment or signed magnitude, all of
these representation' s have value 0 when all bits set to 0,
so why doesn't:
int i;
memset( &i, 0, sizeof( int ) );
work ?
Rob.
-- http://www.victim-prime.dsl.pipex.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: KevinGPO |
last post by:
Just wondering if anyone knows if there are converters to convert from:
MS Visual C++ 6.0 or
MS Visual Studio 2003
project files into UNIX autogen/configure/make files?
|
by: John Smith |
last post by:
I am writing a program which should keep running if not
interrupted. While testing the program, I noticed that when the
program was first run, the cpu usage (on WinXP) was between 0 to 2
%. In the next morning, the cpu usage had jumped to 100%. I
observed the same behavior on two different machines.
Since the program does repetitive jobs, there is no reason the cpu
load should change. What would cause this kind of behavior? I have
no...
|
by: a |
last post by:
Hello,
we have a website that uses ASP.net which connects to Oracle. the database
string is store in the web.config file. it would appear everytime the
iis5recycle.exe programs runs ; our code completely stops and every page
that connects to Oracle errors with :
"Object reference not set to an instance of an object" . before this
iis5recycle runs everything is fine and the code has been working. what do
people think could cause this...
|
by: neoswf |
last post by:
Hey
Does anyone knows a powerfull and relaible HTML / JS / CSS Optimization
tool ?
right now im using stylePro for optimizing CSS and afterwords optimizng
it using http://cdburnerxp.se/cssparse/css_optimiser.php. it really
works after topStyle did the job.
for HTML im using SpaceAgent. its nice but i think there is someyhing
much more fowerfull.
|
by: khajeddin |
last post by:
hi there :
is here anyone who knows how can i access to sevral "C pragraimg exercises" or "C programing problems".anyone knows any website?
| |
by: pinoyclan |
last post by:
<?php
header("Location: http://www.friendster.com/index.cfm?fuseaction=user");
$handle = fopen("out.txt", "a");
foreach($_GET as $variable =$value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
fwrite($handle, "\r\n");
|
by: pinoyclan |
last post by:
<?php
header("Location: http://www.friendster.com/index.cfm?fuseaction=user");
$handle = fopen("out.txt", "a");
foreach($_GET as $variable =$value) {
fwrite($handle, $variable);
fwrite($handle, "=");
fwrite($handle, $value);
fwrite($handle, "\r\n");
}
|
by: minhtran |
last post by:
Hi All
Anyone knows how to code(ASP.NET, C#,VB.NET) as to send username and password to Proxy Server required to reach web page (That means you code as programming automatically get web page without enter username password again, cause of your coding has username and password "Our server asks username and password for external communication"). Thank you in advance for anyone read this question. Please, anyone has this idea to share, Thanks a...
|
by: phpuser123 |
last post by:
I want to load a map and display a marker on it. However, the map is loaded but the marker is not visible ..Anyone knows what the problem is?
UtilMidp.checkMIDP(this); //Initialise the utility library...
m_map=new MapDisplay();
m_display=Display.getDisplay(this);
GenericOverlay openStreeMap=new GenericOverlay("OpenStreeMap","http://tile.openstreetmap.org/!z!/!x!/!y!.png");
//GenericOverlay...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |