473,770 Members | 5,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Porting code, need guidance, Thx


Hi,
I previous posted this in a gcc and g++ groups since that is the
compiler I am working with, but I didn't get any response.

Hopefully these are the right groups for this question. I am working
(actually playing) on porting Alien vs Predator to Linux. I am using
the code that is available via CVS from icculus.org.

I recently upgraded my gcc to 3.4.1 and now a portion of the code
doesn't compile. Nothing in the code has changed.

I think I figured it out, but want to be sure before I spend a bunch of
time working around it only to find that I was wrong.

My guess is the class ConstIterator makes class Iterator a friend, but
class Iterator is a derived class of the bass class ConstIterator (hope
I said that right). From what I understand and have researched is that
in order for the class ConstIterator to use the class Iterator as a
friend, then class Iterator has to be defined first, and for class
Iterator to be derived from class ConstIterator, then the class
ConstIterator has to be defined first. Essentially a catch 22.

Am I on the right track? If not please point me in the right directly,
but I would like to fix the code. I would like to know how you would
approach the fix for this.

Thanks,
Ken

Here is the error:

g++ -g -Wall -pipe -O2 -DLINUX -Dengine=1 -I. -Iinclude -Iwin95 -Iavp
-Iavp/win95 -Iavp/support -Iavp/win95/frontend -Iavp/win95/gadgets
-I/usr/include/SDL -D_REENTRANT -c -o win95/awtexld.o win95/awtexld.cpp
In file included from win95/awtexld.cpp:10:
win95/hash_tem.hpp: In member function `void _base_HashTable <TYPE,
ARG_TYPE, CMP_ARG_TYPE>:: Iterator::Remov e()':
win95/hash_tem.hpp:43 5: error: `nEntriesRemain ing' undeclared (first use
this function)
win95/hash_tem.hpp:43 5: error: (Each undeclared identifier is reported
only once for each function it appears in.)
win95/hash_tem.hpp:43 9: error: `nodePP' undeclared (first use this function)
win95/hash_tem.hpp:44 6: error: `chainPP' undeclared (first use this
function)
win95/hash_tem.hpp:44 7: error: `nChainsRemaini ng' undeclared (first use
this function)
win95/hash_tem.hpp: In copy constructor `_base_HashTabl e<TYPE, ARG_TYPE,
CMP_ARG_TYPE>:: _base_HashTable (const _base_HashTable <TYPE, ARG_TYPE,
CMP_ARG_TYPE>&) ':
win95/hash_tem.hpp:70 5: error: expected `;' before "it"
win95/hash_tem.hpp:70 5: error: `it' undeclared (first use this function)
make: *** [win95/awtexld.o] Error 1

Here is the code in question (not very big, but put in this format so
you can find the lines in question in relation to the errors above):

http://webpages.charter.net/kgroombr/hash_tem.hpp
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Jul 22 '05 #1
5 1638
On Sat, 14 Aug 2004 06:36:00 +0000 (UTC), Kenton Groombridge
<kg******@REMOV EMEcharter.net> wrote:

Hi,
I previous posted this in a gcc and g++ groups since that is the
compiler I am working with, but I didn't get any response.

Hopefully these are the right groups for this question. I am working
(actually playing) on porting Alien vs Predator to Linux. I am using
the code that is available via CVS from icculus.org.

I recently upgraded my gcc to 3.4.1 and now a portion of the code
doesn't compile. Nothing in the code has changed.

I think I figured it out, but want to be sure before I spend a bunch of
time working around it only to find that I was wrong.

My guess is the class ConstIterator makes class Iterator a friend, but
class Iterator is a derived class of the bass class ConstIterator (hope
I said that right). From what I understand and have researched is that
in order for the class ConstIterator to use the class Iterator as a
friend, then class Iterator has to be defined first, and for class
Iterator to be derived from class ConstIterator, then the class
ConstIterator has to be defined first. Essentially a catch 22.
Not correct. One class can be declared as a friend of another without
being declared itself.

Am I on the right track? If not please point me in the right directly,
but I would like to fix the code. I would like to know how you would
approach the fix for this.


This is a change in the rules for dependent name lookup. It's catching a
lot of people out but g++ 3.4 is doing the right thing, whereas older
compilers where not.

For instance in Iterator prefix all references to names in ConstIterator
with this->, so

void Remove()
{
if (!this->nEntriesRemain ing)
{
HT_FAIL("HTT: Tried to Remove() via an iterator which was Done()");
}
Node * oldP = *this->nodePP;
*this->nodePP = oldP->nextP;
delete oldP;
if (!*this->nodePP)
{
do
{
++ this->chainPP;
-- this->nChainsRemaini ng;
}
while (this->nChainsRemaini ng && !*this->chainPP);
this->nodePP = this->chainPP;
}
-- this->nEntriesRemain ing;
-- *tableNEntriesP ;
}

This is explained in the FAQ

http://www.parashift.com/c++-faq-lit...html#faq-34.17

john
Jul 22 '05 #2
Kenton Groombridge wrote:
<snip>
I recently upgraded my gcc to 3.4.1 and now a portion of the code
doesn't compile. Nothing in the code has changed.

I think I figured it out, but want to be sure before I spend a bunch of
time working around it only to find that I was wrong.

My guess is the class ConstIterator makes class Iterator a friend, but
class Iterator is a derived class of the bass class ConstIterator (hope
I said that right). From what I understand and have researched is that
in order for the class ConstIterator to use the class Iterator as a
friend, then class Iterator has to be defined first, and for class
Iterator to be derived from class ConstIterator, then the class
ConstIterator has to be defined first. Essentially a catch 22.
That is a problem, but not the problem that's being reported.
Am I on the right track? If not please point me in the right directly,
but I would like to fix the code. I would like to know how you would
approach the fix for this.

<snip>

I would be inclined to make ConstIterator's member variables
protected. This is not generally a good idea, but I wouldn't want to
go making more drastic changes to the existing code. See
<http://www.parashift.c om/c++-faq-lite/basics-of-inheritance.htm l#faq-19.8>.

I think the errors reported by the compiler are the result of the
change in binding of names in templates that was made in version 3.4
of GNU C++. (The change was made in the standard long ago.) See
<http://www.decadentpla ce.org.uk/womble/cplusplus/template-faq.html#base-lookup>.
Given this, they can be fixed by adding "this->" before the names of
the inherited member variables in the Iterator class. The FAQ I
linked to explains why.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]
Jul 22 '05 #3
Thanks a bunch,

This fixed this issue, but now I have another compile problem. I have
been tinkering with it for several hours but am unsure what it is. The
error is:

win95/hash_tem.hpp: In copy constructor `_base_HashTabl e<TYPE, ARG_TYPE,
CMP_ARG_TYPE>:: _base_HashTable (const _base_HashTable <TYPE, ARG_TYPE,
CMP_ARG_TYPE>&) ':
win95/hash_tem.hpp:70 5: error: expected `;' before "it"
win95/hash_tem.hpp:70 5: error: `it' undeclared (first use this function)
win95/hash_tem.hpp:70 5: error: (Each undeclared identifier is reported
only once for each function it appears in.)
win95/hash_tem.hpp:70 5: error: expected primary-expression before ';' token
win95/hash_tem.hpp:70 5: error: expected `)' before ';' token
win95/hash_tem.hpp:70 5: error: expected `;' before ')' token
make: *** [win95/awtexld.o] Error 1

On line 705 I see where it is calling the copy constructor
_base_HashTable ::ConstIterator it(ht), but all looks good to me. At
least from what I learned. Any guess what could cause this one? My
guess is that line 705 is good, but the error lies somewhere in the copy
constructor, but it also looks good to me.

I have three C++ books and the most recent one is about seven years old.
Have a recommendation on one that will bring me up to speed. Most of
the programs in my books don't compile with gcc 3.4.1 until I do some of
the code fixes that I found with google searching.

Thanks again,
Ken

John Harrison wrote:
Kenton, I never post to moderated groups, in case you missed my reply in comp.lang.c++ here it is direct to your inbox.
John

Jul 22 '05 #4

Kenton Groombridge <kg******@REMOV EMEcharter.net> writes:
Hi,
I previous posted this in a gcc and g++ groups since that is the
compiler I am working with, but I didn't get any response.

Hopefully these are the right groups for this question. I am working
(actually playing) on porting Alien vs Predator to Linux. I am using
the code that is available via CVS from icculus.org.

I recently upgraded my gcc to 3.4.1 and now a portion of the code
doesn't compile. Nothing in the code has changed.
g++ 3.4 implements two-phase lookup as required by the 1998
standard. That makes it in some degree source-code incompatible
with g++ 3.x .

You can find examples on the gcc website; see the 'C++' section of:
http://gcc.gnu.org/gcc-3.4/changes.html
I think I figured it out, but want to be sure before I spend a bunch of
time working around it only to find that I was wrong.

My guess is the class ConstIterator makes class Iterator a friend,
This is true but irrevelant. Friendship affects access control, not
namelookup. No declaration for 'nEntriesRemain ing' is found,
therefor the issue is namelookup. This is in fact akin to one of
the examples on the gcc 3.4 changes page I linked to above.
but
class Iterator is a derived class of the bass class ConstIterator (hope
I said that right).
Correct.
From what I understand and have researched is that
in order for the class ConstIterator to use the class Iterator as a
friend, then class Iterator has to be defined first,
A definition is *not* necessary. Only a forward declaration is
necessary - and in some cases the friend declaration itself can
fulfill this purpose. But the whole friend issue is irrevelant.
and for class
Iterator to be derived from class ConstIterator, then the class
ConstIterator has to be defined first.
True.
Essentially a catch 22.
No, becuase declaring something friend does not require a definition
- but, as I said before, the whole friend issue is irrevelant.

[snip] I would like to know how you would
approach the fix for this.

[snip]

Replace 'nEntriesRemain ing' whith 'this->nEntriesRemain ing'.

The Vandervoode and Josuttis _C++ Templates_ book has a section on
dependent names which I think explains why this works.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.m oderated. First time posters: Do this! ]

[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Jul 22 '05 #5
I finally figured this one out. I got to get used to the stricter rules
of the C++ standard. I also need some new books which stick to these
standards since most of the programs in my books no longer compile with
gcc 3.1. Been programming the wrong way for a long time. Anybody that
has book recommendations that stick with the strict C++ standard, please
respond. All my books are at least 7 to 12 years old.

Here is the fix for anybody that has issue with anything like this:

The error is on line 705 which is:

for (_base_HashTabl e::ConstIterato r it(ht); !it.Done(); it.Next() )
The fix is:

for (typename _base_HashTable ::ConstIterator it(ht); !it.Done();
it.Next() )

as found on:

http://gcc.gnu.org/gcc-3.4/changes.html

which states:

You must now use the typename and template keywords to disambiguate
dependent names, as required by the C++ standard.
Kenton Groombridge wrote:
Thanks a bunch,

This fixed this issue, but now I have another compile problem. I have
been tinkering with it for several hours but am unsure what it is. The
error is:

win95/hash_tem.hpp: In copy constructor `_base_HashTabl e<TYPE, ARG_TYPE,
CMP_ARG_TYPE>:: _base_HashTable (const _base_HashTable <TYPE, ARG_TYPE,
CMP_ARG_TYPE>&) ':
win95/hash_tem.hpp:70 5: error: expected `;' before "it"
win95/hash_tem.hpp:70 5: error: `it' undeclared (first use this function)
win95/hash_tem.hpp:70 5: error: (Each undeclared identifier is reported
only once for each function it appears in.)
win95/hash_tem.hpp:70 5: error: expected primary-expression before ';' token
win95/hash_tem.hpp:70 5: error: expected `)' before ';' token
win95/hash_tem.hpp:70 5: error: expected `;' before ')' token
make: *** [win95/awtexld.o] Error 1

Jul 22 '05 #6

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

Similar topics

2
3372
by: eichin | last post by:
One of my recent projects has involved taking an accretion of sh and perl scripts and "doing them right" - making them modular, improving the error reporting, making it easier to add even more features to them. "Of course," I'm redoing them in python - much of the cut&paste reuse has become common functions, which then get made more robust and have a common style and are callable from other (python) tools directly, instead of having to...
7
2151
by: Sonny | last post by:
I need to port a library that is written entirely in C to C++. The library is supported on quite a few platforms (windows, Solaris, Linux, AIX, HP-UX, OSX, etc...) and there's quite an existing customer base that uses it. I need to maintain backwards compatibility such that existing users won't have to do anything to their existing applications other than a re-compile when they upgrade to this new version of the library. I figure that I...
4
2394
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light, fast database abstraction layer which conforms to the behavior of the MySQL functions in PHP. This means that a large amount of porting work could be made simple using this porting layer if the application was originally used PHP's native MySQL...
1
1472
by: Robin Charisse | last post by:
Hi, I have a VC++6 project that uses msxml to parse XML documents. I have been asked to port this to a .NET project but from the research I've done so far it looks as though the only way to do this is to rewrite the project from scratch in C#. Time is at a premium and given that I have no prior experience of either C# or Visual Studio .NET, this is not an acceptable solution. Is there any other way of doing this without wholesale code...
16
2140
by: Mohanasundaram | last post by:
Hi All, We are working on porting a product written in C and C++ from 32 bit to 64 bit. We need to maintain both 32 bit and 64 bit versions in the future. We took the 32 bit source code and copiled it using a 64 bit compiler and fixed all the compilation warnings. Compilation went through fine but the product breaks in lots of places. We understood that porting a 32 bit code to 64 bit platform is not just a matter of compilation. We...
4
1985
by: Ian | last post by:
I would like to hear from others who have considered and/or ported code from traditional C++ to C++/CLI. The class library I am considering porting to C++/CLI was written in traditional C++ with STL and a touch of MFC. It represents the back end to my applications and, among a number of other things, it performs all file I/O and data management operations (i.e. no GUI). Why would I consider porting it to C++/CLI when it works just...
2
3844
by: sandip desale | last post by:
Dear All, We have a Tcl/Tk application written using Python 2.2. Using this application we want to call some customizable Java APIs. I tried porting Tcl/Tk application to Jython but not able to do the same as TKinter library is not available with JYthon. Can you please help me in porting Tkinter application to Jython? Also kindly let me know how to do the same. Thanks & Regards, Sandip Desale
34
4077
by: subramanian100in | last post by:
Is there any difference between porting and migrating. Kindly explain
5
2631
by: slim9913 | last post by:
I worked on c/c++ executable file building on Windows platform before. Now, there is a need to port my c/c++ program from Windows to UNIX platform, and I have no experience in this at all. Anybody have step by step guidance on the porting work? First thing that I faced is, it has #include <windows.h> on Windows, what is the equivalent in Unix? Thanks a lot.
0
9425
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,...
0
10231
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
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...
1
10005
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,...
0
9871
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 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...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
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
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
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...

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.