Re: Porting from Windows to Linux
From: Prasanna (prasan8181_at_dacafe.com)
Date: 06/18/04
- Next message: David Harmon: "Re: creating methods for objects"
- Previous message: JustSomeGuy: "why won't this complile??? const troubles..."
- In reply to: Ioannis Vranos: "Re: Porting from Windows to Linux"
- Next in thread: Ioannis Vranos: "Re: Porting from Windows to Linux"
- Reply: Ioannis Vranos: "Re: Porting from Windows to Linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Jun 2004 12:32:27 -0700
I was able to locate the problem. The problem is:
class GF{
public:
GF(){};
GF(vector<unsigned>);
GF(vector<unsigned>, unsigned);
GF(GF&);
GF& operator=(vector<unsigned>&);
GF& operator=(GF&);
vector<unsigned> primitive();
vector<unsigned> element();
protected:
vector<unsigned> ir;
vector<unsigned> el;
};
I am using the above class in a code segment like this:
//////////////
....
vector<GF> f;
GF local;
f.push_back(local); // just to demonstrate the problem
unsigned m = f.size();
for(int i=0;i<m;i++)
f[i] = GF(local.primitive(),i).element(); //<-- this is where it
crashes
.....
//////////////
What i want the above line to do is create a GF object and assign its
element to f[i] using operator =. VC++ is doing only that. But gcc
does the following. It creates a GF object and uses its element
returned by GF::element() to create another GF object using the
GF::GF(vector<unsigned>) constructor and then uses GF::operator=(GF&)
to assign it to f[i].
May be this is a ill formed situation. But neither gcc nor vc++ issues
any warnings about it. Can u suggest me some good solution, coz i also
want this GF::GF(vector<unsigned>). That makes usage of the class
quite easier.
Regards,
Prasanna.
Ioannis Vranos <ivr@guesswh.at.grad.com> wrote in message news:<caue90$1af8$1@ulysses.noc.ntua.gr>...
> Prasanna wrote:
> > Hi,
> >
> > I have been developing some libraries using VC++ 6.0. My work is
> > complete now and the code works just fine. It has been tested under
> > many circumstances and i have not encountered any problems. Now, I
> > would like to port it to gcc. Initially compiling it with gcc produced
> > a few errors, asking for some 'const' declarations in places where
> > VC++ would not bother to. But then, i was able to compile it and
> > create an executable. The problem is the executable crashes when i run
> > it.
> >
> > I tried it with cygwin latest version and g++ in suse 8.1. When i
> > tried to debug it with DDD in suse, the program halts when i am
> > returning a reference. I checked for possible memory problems, like
> > returning a reference for a local variable or chaning the address of
> > an allocated memory. But there are none like that.
> >
> > For example, the place where my program halts is this:
> >
> > vector<unsigned>& GF::primitive()
> > {
> > return ir;
> > }
> >
> > where 'ir' is a protected data member of class GF, as shown.
> >
> > class GF{
> > ....
> > protected:
> > vector<unsigned> ir;
> > };
> >
> > If i try to step through return, it goes inside vector class and i get
> > lost.
> > I have no idea why this happens. Can someone elighten me on this.
> >
> > Regards,
> > Prasanna.
>
>
>
> Does the following code crash to you?
>
>
> #include <vector>
>
>
> int main()
> {
> using std::vector;
>
> class test
> {
> protected:
> vector<unsigned>ir;
>
> public:
> vector<unsigned>& primitive() { return ir; }
> };
>
>
> test a;
>
> vector<unsigned> &rir=a.primitive();
> }
>
>
>
>
>
>
> Regards,
>
> Ioannis Vranos
- Next message: David Harmon: "Re: creating methods for objects"
- Previous message: JustSomeGuy: "why won't this complile??? const troubles..."
- In reply to: Ioannis Vranos: "Re: Porting from Windows to Linux"
- Next in thread: Ioannis Vranos: "Re: Porting from Windows to Linux"
- Reply: Ioannis Vranos: "Re: Porting from Windows to Linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|