Unix Programming - A C++ core dump

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2005 > A C++ core dump





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author A C++ core dump
Benjamin Wang

2005-01-25, 2:52 am

Greeting,

Recently, I met a very strange problem about C++ code on solaris 8.

I have a program and it looks like as below:
..h file:
class scheduler {
.......
public:

static KeyMeasGroups measGroups;

void mainLoop();

void handleOneUsageCount( );
........
};
==============
..cpp file:

KeyMeasGroups Scheduler::measGroups;

Scheduler::Scheduler( )
{
...............
if( measGroups.init() < 0)
return;
..............
}

For some reason, I changed the code as below:

..h file:
class scheduler {
.......
public:

static KeyMeasGroups * measGroups;

KeyMeasGroups measGroupsIns1;
KeyMeasGroups measGroupsIns2;

void mainLoop();

void handleOneUsageCount( );
........
};
==============
..cpp file:

KeyMeasGroups * Scheduler::measGroups;
KeyMeasGroups Scheduler::measGroupsIns1;
KeyMeasGroups Scheduler::measGroupsIns2;

Scheduler::Scheduler( )
{
...............
if( measGroupsIns1.init() < 0)
return;
measGroups = &measGroupsIns1;
..............
}

But I got core dump, and the program coredump at the beginning of main().
I try to analysis the core file with dbx, but pathmap seems not work well.

Could you tell me the impossible reasons for it? or how to debug this kind
of problem?

Thanks very much for your help.


David Schwartz

2005-01-25, 7:49 am


"Benjamin Wang" <zwang2@lucent.com> wrote in message
news:ct50p8$a69@netnews.proxy.lucent.com...

> Scheduler::Scheduler( )
> {
> ..............
> if( measGroups.init() < 0)
> return;
> .............
> }


This requires that measGroups be contructed before any Scheduler is
constructed. What in your code assures this?

DS


John Smith

2005-01-25, 5:52 pm

Just a minor note:

KeyMeasGroups measGroupsIns1;
KeyMeasGroups measGroupsIns2;

These are not declared static but are created as if they were static. How
can this be?

-- John


David Schwartz

2005-01-25, 8:47 pm


"John Smith" <john.smith@x-formation.com> wrote in message
news:41f6b885$0$33727$edfadb0f@dread16.news.tele.dk...
> Just a minor note:
>
> KeyMeasGroups measGroupsIns1;
> KeyMeasGroups measGroupsIns2;
>
> These are not declared static but are created as if they were static. How
> can this be?


What does "created as if they were static" mean? In this context,
'static' only affects link visibility, not creation time or mechanism.

DS


John Smith

2005-01-26, 6:02 pm

> What does "created as if they were static" mean? In this context,
> 'static' only affects link visibility, not creation time or mechanism.


In the code provided it says:

class scheduler {
.......
public:

static KeyMeasGroups * measGroups;

KeyMeasGroups measGroupsIns1; <- Notice no static keyword
KeyMeasGroups measGroupsIns2;
....
};

In cpp file:

KeyMeasGroups Scheduler::measGroupsIns1;
KeyMeasGroups Scheduler::measGroupsIns2;

There is no 'static' keyword infront of the variables inside the class.
I'm quite surprised the code compiles at all. If no static keyword is
supplied you need to create an object and thus the static creation in the
cpp file is not allowed. Otherwise you need one instance and need to supply
static keyword.

Makes sense?

-- John


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com