473,409 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Porting from Windows to Linux

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.
Jul 22 '05 #1
9 1394
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;
};


The debugger should tell you more, like the parameters (including the
'this' pointer). Maybe on the call to primitive, 'this' was a null
pointer.
Jul 22 '05 #2
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
Jul 22 '05 #3
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 <iv*@guesswh.at.grad.com> wrote in message news:<ca***********@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

Jul 22 '05 #4
Prasanna wrote:
I was able to locate the problem. The problem is:

Ok let's give it a try.

class GF{

public:
GF(){};
GF(vector<unsigned>);
GF(vector<unsigned>, unsigned);

The above two have as a result vectors with all their contents to be
copied with the space and time cost this implies. I do not know which
vector (ir or el) you initialize with the vector<unsigned> above but
here is an example:
GF(const vector<unsigned> &v):ir(v) { // or ir=v; }
GF(const vector<unsigned> &v, unsigned x): ir(v) { // whatever else }

GF(GF&);
// Type safety
GF(const GF &);


GF& operator=(vector<unsigned>&);
Better defined outside of the class as

// const again too
GF& operator=(GF &, const vector<unsigned>&);

GF& operator=(GF&);
GF& operator=(const GF&);

vector<unsigned> primitive();
vector<unsigned> element();

These two return these or references? If you need only the values and
not direct access to ir, el you had better make the above
// References returned, run-time efficiency
const vector<unsigned> &primitive() const;
const vector<unsigned> &element() const;

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();

vector<GF>::size_type m=f.size();

but is not needed anyway, see below.

for(int i=0;i<m;i++)

for(vector<GF>::size_type i=0; i<f.size(); ++i)
f[i] = GF(local.primitive(),i).element(); //<-- this is where it
crashes

Many conversions take place here. However you are passing i which has
the value 0 and i do not know how you use the unsigned inside the
implementation of GF constructor. Perhaps the problem lies there.

However i have not understood what you want to do with the above. Why
create a temporary GF in the first place?

......
//////////////

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

Yes, because f[i] is a GF object, while GF::element() returns a
vector<unsigned> object, so implicit type conversion is taking place in
both compilers. Of course a compiler can optimise some of these
conversions out, if possible. However we must think without any such
compiler optimisations in mind.
If possible, provide the implementations of all the constructors.


Regards,

Ioannis Vranos
Jul 22 '05 #5
Ioannis Vranos wrote:
GF& operator=(vector<unsigned>&);
Better defined outside of the class as


Why?

// const again too
GF& operator=(GF &, const vector<unsigned>&);


That won't compile. operator= cannot be defined as non-member.

Jul 22 '05 #6
Rolf Magnus wrote:
That won't compile. operator= cannot be defined as non-member.


Oops you are right. I had to define an operator for some time and I have
become rusty.


Regards,

Ioannis Vranos
Jul 22 '05 #7
> The above two have as a result vectors with all their contents to be
copied with the space and time cost this implies. I do not know which
vector (ir or el) you initialize with the vector<unsigned> above but
here is an example:
GF(const vector<unsigned> &v):ir(v) { // or ir=v; }
GF(const vector<unsigned> &v, unsigned x): ir(v) { // whatever else }

I intialize ir. And i have changed it to the references.
These two return these or references? If you need only the values and
not direct access to ir, el you had better make the above
// References returned, run-time efficiency
const vector<unsigned> &primitive() const;
const vector<unsigned> &element() const;
I will change these too. The thing is STL gave me a lot of problems
with using references and consts', expecially with this operator ==.
So i messed up my code a bit.

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();

vector<GF>::size_type m=f.size();

but is not needed anyway, see below.


But why? That makes the code harder to read is not it? I have no idea
to what type is vector<T>::size_type defined to.
for(int i=0;i<m;i++)

for(vector<GF>::size_type i=0; i<f.size(); ++i)
f[i] = GF(local.primitive(),i).element(); //<-- this is where it
crashes

Many conversions take place here. However you are passing i which has
the value 0 and i do not know how you use the unsigned inside the
implementation of GF constructor. Perhaps the problem lies there.
However i have not understood what you want to do with the above. Why
create a temporary GF in the first place?

It is not absolutely required (creating a local variable). To explain
it, the objects are some kind of polynomials. What i do in the
constructor is to create one such polynomial of degree i. I can
ofcourse change it by creating a initial constant and then shifting it
(which is multiplying it by x). But that is not the exact problem
because the code also crashes in the following place.

for(i=0;i<=fx.degree();i++){
irp.push_back(baserep);
irp[i] = fx[i].element();
}

And the problem is the same. gcc uses the constructor than using the
operator =.
Yes, because f[i] is a GF object, while GF::element() returns a
vector<unsigned> object, so implicit type conversion is taking place in
both compilers. Of course a compiler can optimise some of these
conversions out, if possible. However we must think without any such
compiler optimisations in mind.
I did not have any compiler optimizations in mind. What vc++ does is
what i had in mind and it seemed obvious to me that the expression
should be handled that way. Well.. i am learning.
If possible, provide the implementations of all the constructors.


I have pasted below the implementations of some of the overloaded
constructors. It is lot of code reuse, but i dont see any other ways.
:(

GF2m::GF2m() {
irp.push_back(0); elm.push_back(0);
}

GF2m::GF2m(const vector<unsigned>& irr)
{
int i,m,s;
m = irr.size();
if(m!=0){
//! first copy the irreducible polynomial
irp = irr;
//! then, for modular reduction, precompure x^m term
for(i=m-2;i>=0;i--)
if(irp[i]!=0)
break;
s=i;
for(i=0;i<=s;i++)
xm.push_back(irp[i]);
}
else
irp.push_back(0);

elm.push_back(0);
}

GF2m::GF2m(const vector<unsigned>& irr, unsigned exp)
{
int i,m,s;
m = irr.size();
if(m!=0){
irp = irr;
for(i=m-2;i>=0;i--)
if(irp[i]!=0)
break;
s=i;
for(i=0;i<=s;i++)
xm.push_back(irp[i]);
}
else
irp.push_back(0);

elm.resize(exp+1);
//! form, x^k, k = exp;
for(i=0;i<exp;i++)
elm[i]=0;
elm[exp] = 1;

if(exp>=m-1)
reduce(); //! reduce modulo irreducible
}

GF2m::GF2m(const vector<unsigned>& irr, vector<unsigned> e)
{
int i,m;
m = irr.size();
if(m!=0){
irp = irr;
for(i=m-2;i>=0;i--)
if(irp[i]!=0)
break;
unsigned s=i;
for(i=0;i<=s;i++)
xm.push_back(irp[i]);
}
else
irp.push_back(0);

if(!e.empty())
elm = e;
else
elm.push_back(0);

}

Best regards,
Prasanna.
Jul 22 '05 #8
Prasanna wrote:
I will change these too. The thing is STL gave me a lot of problems
with using references and consts', expecially with this operator ==.
So i messed up my code a bit.

The safety of the type system is there to help and protect you, provided
that you use it correctly (e.g. declare as constant only things not
intended to be modified).

vector<GF>::size_type m=f.size();

but is not needed anyway, see below.

But why? That makes the code harder to read is not it? I have no idea
to what type is vector<T>::size_type defined to.


vector<T>::size_type is the type returned from vector<T>::size() member
function. In most cases it is a typedef of an unsigned integral type.

However there may be a specialisation for a particular T type, even from
you for a type of yours. As you can understand, you can go really
abstract and you are limited only by your imagination to create
"things". :-)

To be portable it is better to use size_type instead of size_t since it
is the type returned by size(). If you are tired to write
vector<GF>::size_type all the time you can do a typedef:
typedef vector<GF>::size_type size;

// ...

for(size i=0; i<f.size() ++i)
// ...
// ...

for(size i=0; i<f.size() ++i)
// ...

It is not absolutely required (creating a local variable). To explain
it, the objects are some kind of polynomials. What i do in the
constructor is to create one such polynomial of degree i.
Ok you had written:
"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;
};

//////////////
......
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
.......
//////////////"

The local.primitive() in the constructor call returns an *empty*
vector<unsigned>, and i used is 0. I think the first or the second or
both is the reason of the crash.




I can ofcourse change it by creating a initial constant and then shifting it
(which is multiplying it by x). But that is not the exact problem
because the code also crashes in the following place.

for(i=0;i<=fx.degree();i++){
irp.push_back(baserep);
irp[i] = fx[i].element();
}

And the problem is the same. gcc uses the constructor than using the
operator =.

Yes, because f[i] is a GF object, while GF::element() returns a
vector<unsigned> object, so implicit type conversion is taking place in
both compilers. Of course a compiler can optimise some of these
conversions out, if possible. However we must think without any such
compiler optimisations in mind.

I did not have any compiler optimizations in mind. What vc++ does is
what i had in mind and it seemed obvious to me that the expression
should be handled that way. Well.. i am learning.

Whatever the optimisations the result should be the same, otherwise that
would mean that it can't be optimised.

If possible, provide the implementations of all the constructors.

I have pasted below the implementations of some of the overloaded
constructors. It is lot of code reuse, but i dont see any other ways.
:(

GF2m::GF2m() {
irp.push_back(0); elm.push_back(0);
}

GF2m::GF2m(const vector<unsigned>& irr)
{
int i,m,s;
m = irr.size();


vector<unsigned>::size_type i, m, s;

etc.. Or at least an unsigned built in integral type, like unsigned.
if(m!=0){
//! first copy the irreducible polynomial
irp = irr;
//! then, for modular reduction, precompure x^m term
for(i=m-2;i>=0;i--)
if(irp[i]!=0)
break;
s=i;
for(i=0;i<=s;i++)
xm.push_back(irp[i]);
}
else
irp.push_back(0);

elm.push_back(0);
}

GF2m::GF2m(const vector<unsigned>& irr, unsigned exp)
{
int i,m,s;
m = irr.size();
if(m!=0){
irp = irr;
for(i=m-2;i>=0;i--)
if(irp[i]!=0)
break;
s=i;
for(i=0;i<=s;i++)
xm.push_back(irp[i]);
}
else
irp.push_back(0);

elm.resize(exp+1);
//! form, x^k, k = exp;
for(i=0;i<exp;i++)
elm[i]=0;
elm[exp] = 1;

if(exp>=m-1)
reduce(); //! reduce modulo irreducible
}

GF2m::GF2m(const vector<unsigned>& irr, vector<unsigned> e)
{
int i,m;
m = irr.size();
if(m!=0){
irp = irr;
for(i=m-2;i>=0;i--)
if(irp[i]!=0)
break;
unsigned s=i;
for(i=0;i<=s;i++)
xm.push_back(irp[i]);
}
else
irp.push_back(0);

if(!e.empty())
elm = e;
else
elm.push_back(0);

}

Ok i 'll try to check the above tomorrow, however in the mean time try
to use vector::at() in the place of [], which is range checked, for example:

for(i=m-2;i>=0;--i)
if(irp.at(i)!=0)
break;
vector<>::at() throws an exception if its index is out of range.


Regards,

Ioannis Vranos
Jul 22 '05 #9
Ioannis Vranos wrote:

Typos fixed:

To be portable it is better to use size_type instead of size_t since it
is the type returned by size(). If you are tired to write
vector<GF>::size_type all the time you can do a typedef:

typedef vector<GF>::size_type Size;

// ...

for(Size i=0; i<f.size() ++i)
// ...
// ...


for(Size i=0; i<f.size() ++i)
// ...


Regards,

Ioannis Vranos
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Sgier | last post by:
Hello i'm trying to port a windows program to linux with Kdevelop 1.question: unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader); ...
6
by: Raghavendra | last post by:
Hi All, I have one big system application, which is developed for HPUX and Windows in C-language. I need to port it to Linux. What all things do I need to consider to do this. Can you please...
1
by: Sunanda | last post by:
Hi, I am a newbie to .Net. I have an application in running in linux, a set of .c and .h files. I also have a makefile in linux to create the executable. I want to port this to windows...
4
by: Chuck Chopp | last post by:
I have an application that I originally built using Visual Studio .NET 2003 as native C++ . This application includes a template class that was derived from the string class that's part of the C++...
13
by: jc | last post by:
I have written a parser using bison and flex to read ASAP2 file for CAN communications. entire development was done in an unix environment and now the code is ready to be integrated to an existing...
7
by: Lior | last post by:
Hi, I have small code, that compiles on Visual C++ into a shared library (DLL). I need to compile it under linux, but the code includes some data types I'm not familiar with, such as DWORD,...
0
by: Michael Palmer | last post by:
On Sep 16, 12:30 pm, binaryjesus <coolman.gu...@gmail.comwrote: I haven't tried it myself, but I came across a blog post the other day that describes a way of building windows installers for...
47
by: =?Utf-8?B?ZW1hdmlzdQ==?= | last post by:
Dear guys, I'm in trouble having to port my project from C++Builder6 to VisualC++. Has anyone of you idea if there are any tools to help my doing this job? My current project is widely using VCL...
19
by: Dotan Cohen | last post by:
I often see mention of SMBs that either want to upgrade their Windows installations, or move to Linux, but cannot because of inhouse VB apps. Are there any Python experts who I can reference them...
0
by: Ed Leafe | last post by:
On Oct 18, 2008, at 8:12 AM, Dotan Cohen wrote: Sorry for the delay in responding, but someone just pointed out this post to me. You might want to take a look at Dabo, which is an integrated...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.