Welcome, Guest. Please login or register.

Author Topic: C++ on Amiga  (Read 14925 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline NovaCoder

Re: C++ on Amiga
« Reply #14 on: August 31, 2009, 07:23:02 AM »
Quote from: matthey;521559
C IS slower than assembler. GCC's code optimization is a joke. Why is ffmpeg for the 68060 twice as fast with a few assembler routines compared to all C routines? I don't know much about C++ compared to C but I have seen too much assembly output from C programs to believe C is as fast as assembler. Plus I can beat it 95% of the time with assembler.



Well obviously over the years C/C++ compilers have improved massively and these days you'll improve performance more from looking at what the code is doing from a high-level rather than trying to hand-optimize algorithms (the quickest code is code you don't actually execute).  

I remember reading an assembler 'tuning' article which had an exercise to improve some compiler generated assembler by-hand.  When I went to make the change myself, I found that my newer version of the compiler had already produced exactly the same assembler as the article suggested ;)

I wasn't talking specifically about GCC, I was talking about modern compilers C++ in general.
« Last Edit: September 01, 2009, 12:40:31 AM by NovaCoder »
Life begins at 100 MIPS!


Nice Ports on AmiNet!
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: C++ on Amiga
« Reply #15 on: August 31, 2009, 11:25:01 AM »
Quote from: matthey;521559
C IS slower than assembler. GCC's code optimization is a joke. Why is ffmpeg for the 68060 twice as fast with a few assembler routines compared to all C routines? I don't know much about C++ compared to C but I have seen too much assembly output from C programs to believe C is as fast as assembler. Plus I can beat it 95% of the time with assembler.

This may be true for m68k compilers of the vintage in use on the amiga, but it isn't necessarily true of compilers in general. In any event, C and C++ both let you use assembler where you aren't satisfied with the compiler's code generation efforts.

Writing something entirely in assembler is massively wasteful in terms of development time.
int p; // A
 

Offline zylesea

  • Hero Member
  • *****
  • Join Date: Feb 2006
  • Posts: 638
    • Show only replies by zylesea
    • http://www.via-altera.de
Re: C++ on Amiga
« Reply #16 on: August 31, 2009, 01:19:37 PM »
Get a copy of Cubic IDE http://devplex.awardspace.biz/

It is a powerful package for programming C/C++, Hollywood, HTML and much more. It comes with vbcc and gcc (for sevral amigaish OSes) as well as a lot of documentation. The project mangement helps you with makefiles and to do your first "hello world" programm in C++ it takes only a couple of minutes.
Cubic is IMO one of the last software gems on Amiga & Co.

Offline SamuraiCrow

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2280
  • Country: us
  • Gender: Male
    • Show only replies by SamuraiCrow
Re: C++ on Amiga
« Reply #17 on: August 31, 2009, 03:40:49 PM »
Quote from: Karlos;521568
This may be true for m68k compilers of the vintage in use on the amiga, but it isn't necessarily true of compilers in general. In any event, C and C++ both let you use assembler where you aren't satisfied with the compiler's code generation efforts.

Writing something entirely in assembler is massively wasteful in terms of development time.

You mean non-68k compilers in general.  GCC 4.4.x generates slow code for the 68k and sometimes buggy because 68k today means only embedded controller use and not mainstream computing any more.  It generates much worse code than for a PowerPC or Intel x86.
 

Offline hayashiTopic starter

  • Jr. Member
  • **
  • Join Date: Jan 2009
  • Posts: 82
    • Show only replies by hayashi
    • http://www.d-linc.co.uk
Re: C++ on Amiga
« Reply #18 on: August 31, 2009, 04:27:18 PM »
NOOB QUESTION INCOMING

Does the 3.9NDK work with C++ or just C?
[UK] A1200 with 2GB hard drive and Apollo 1240 040/33MHz/16MB FastRAM | A500+ with trapdoor memory upgrade and A520 modulator and no battery or power supply

Floppy Drive Grim Reaper and DPaint lover
 

Offline SamuraiCrow

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2280
  • Country: us
  • Gender: Male
    • Show only replies by SamuraiCrow
Re: C++ on Amiga
« Reply #19 on: August 31, 2009, 04:33:48 PM »
A few of the headers may require modification to work under C++ but don't ask me which ones.  They will all work under C though.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: C++ on Amiga
« Reply #20 on: August 31, 2009, 04:40:04 PM »
Quote from: hayashi;521600
NOOB QUESTION INCOMING

Does the 3.9NDK work with C++ or just C?

It works fine with both, with one caveat. In C++, the use of the struct keyword when referring to a type is deprecated. This can lead to an ambiguity (it happened to me once) where you have global variables and structures with the same name.

Somewhere in your NDK, you have:

extern struct IntuitionBase* IntuitionBase;

Now, this is isn't great. It isn't a good idea to mix up variable names and structure names.

However, in C:

IntuitionBase = (struct IntutionBase*)OpenLibary("intuition.library", 0);

is fine. The global variable on the left of the assignment is completely distinct from the typename on the right, due to the struct keyword.

In C++, this above use of the struct keyword is deprecated and can cause your compiler to moan. However, removing it, can cause a problem:

IntuitionBase = (IntutionBase*)OpenLibary("intuition.library", 0); // huh?

The compiler may not know how to interpret the left hand side. Is it an incomplete reference to something?

The solution that worked for me is to disambiguate the reference by explicitly pointing out the global namespace, using the scope of resolution operator ( :: ), thus:

::IntuitionBase = (IntuitionBase*)OpenLibrary("intuition.library, 0);

Now the compiler knows you mean the global variable called IntuitionBase, and not the type name IntuitionBase.

Quote
A few of the headers may require modification to work under C++ but don't ask me which ones. They will all work under C though.

If you keep the caveat above in mind, this isn't the case.
« Last Edit: August 31, 2009, 04:43:24 PM by Karlos »
int p; // A
 

Offline amigadave

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: Jul 2004
  • Posts: 3836
    • Show only replies by amigadave
    • http://www.EfficientByDesign.org
Re: C++ on Amiga
« Reply #21 on: August 31, 2009, 08:49:21 PM »
Quote from: NovaCoder;521543
Yep I think the idea that C++ is slower is not accurate these days, it's similar to the idea the C is slower than assembler (modern compilers produce very efficient assembler).

Anyway I've been using C++ on my 1200 for a port of DOTT.

I use StormC V4 which uses the GCC compiler and features an IDE with built in debugger which makes everything a lot easier.  You can still buy StromC V4 new for about $50.

It will take you longer to learn C++ of course, I spent a year learning straight C before I started looking at C++.

Some books, or articles have suggested that learning C first before learning C++ may actually slow down the learning process and that learning C first is not necessary, or really desirable.  Is that accurate in your opinion, or do you think that it helped you by learning C first then moving on to C++?
How are you helping the Amiga community? :)
 

Offline bloodline

  • Master Sock Abuser
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 12113
    • Show only replies by bloodline
    • http://www.troubled-mind.com
Re: C++ on Amiga
« Reply #22 on: August 31, 2009, 08:58:45 PM »
I don't really see the point of learning C first, just learn C++. Once you understand C++, C will become apparent.

Offline matthey

  • Hero Member
  • *****
  • Join Date: Aug 2007
  • Posts: 1294
    • Show only replies by matthey
Re: C++ on Amiga
« Reply #23 on: September 01, 2009, 12:26:11 AM »
@NovaCoder

C optimizing is getting better but it's not there yet with GCC 68k. GCC will do a pretty good job on some things and then add a nop or exg d0,d0 in there. I've been debugging Warp3D lately to try and fix a bug and I keep seeing those darn exg d0,d0. The wasted instructions even make for difficult reading. I wan't to fix everyone of them. For all the poor code, GCC code amazingly rarely crashes. The newest versions of GCC are worse at optimizing than the older versions by the way. I wouldn't be surprised if VBCC and SASC generate better code.
« Last Edit: September 01, 2009, 12:32:46 AM by matthey »
 

Offline NovaCoder

Re: C++ on Amiga
« Reply #24 on: September 01, 2009, 12:44:18 AM »
Quote from: amigadave;521620
Some books, or articles have suggested that learning C first before learning C++ may actually slow down the learning process and that learning C first is not necessary, or really desirable.  Is that accurate in your opinion, or do you think that it helped you by learning C first then moving on to C++?


Yep I think it helped me to learn C first (although it was a bit boring).  It's quite a big brain-space jump to think about proper object orientation and you don't want the extra strain of learning the language syntax.

I'd only used Basic before getting into C/C++ so it was a steep learning curve for me :)
« Last Edit: September 01, 2009, 05:14:51 AM by NovaCoder »
Life begins at 100 MIPS!


Nice Ports on AmiNet!
 

Offline hayashiTopic starter

  • Jr. Member
  • **
  • Join Date: Jan 2009
  • Posts: 82
    • Show only replies by hayashi
    • http://www.d-linc.co.uk
Re: C++ on Amiga
« Reply #25 on: September 01, 2009, 01:08:34 AM »
I use Python as my main language, so I already have some idea of the concepts behind object-oriented programming.
[UK] A1200 with 2GB hard drive and Apollo 1240 040/33MHz/16MB FastRAM | A500+ with trapdoor memory upgrade and A520 modulator and no battery or power supply

Floppy Drive Grim Reaper and DPaint lover
 

Offline persia

  • Hero Member
  • *****
  • Join Date: Sep 2006
  • Posts: 3753
    • Show only replies by persia
Re: C++ on Amiga
« Reply #26 on: September 01, 2009, 03:47:47 AM »
I'm a fairly good objective C programmer, how different is C++ to Obj C?
[SIGPIC][/SIGPIC]

What we\'re witnessing is the sad, lonely crowing of that last, doomed cock.
 

Offline amigadave

  • Lifetime Member
  • Hero Member
  • *****
  • Join Date: Jul 2004
  • Posts: 3836
    • Show only replies by amigadave
    • http://www.EfficientByDesign.org
Re: C++ on Amiga
« Reply #27 on: September 01, 2009, 05:12:37 AM »
Quote from: bloodline;521624
I don't really see the point of learning C first, just learn C++. Once you understand C++, C will become apparent.

That seems to be the popular thinking these days.  That it is pointless to learn C anymore and more efficient to just jump into C++ as long as the person learning has some programming experience in any other language, or a very basic understanding of logic and perhaps some kind of scripting.
How are you helping the Amiga community? :)
 

Offline AmigaHeretic

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 821
    • Show only replies by AmigaHeretic
Re: C++ on Amiga
« Reply #28 on: September 16, 2009, 12:46:18 AM »
Anyobdy have a m68k GCC w/ SDL folder that works that they can just zip and send.

I can not get SDL to work for the life of me.  Tried both GCC 3.4 and 4.3.2 which work fine, but I can't get SDL to work.  ( Using 1.2.13(r2) )  

Or at least confirm they work together on OS3.9 just so I can sleep at night! ;-)

Visual studio is like 4GB now, but at least I can just hit build.  Ah, programming for dummies.
A3000D (16mhz, 2MB Chip, 4MB Fast, SCSI (300+MB), SuperGen Genlock, Kick 3.1)
Back in my day, we didn\'t have water. We only had Oxygen and Hydrogen, and we\'d just have to shove them together.
 

Offline AmigaHeretic

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 821
    • Show only replies by AmigaHeretic
Re: C++ on Amiga
« Reply #29 from previous page: September 17, 2009, 03:05:13 AM »
Got it working finally.  Compiled my first SDL demo.
A3000D (16mhz, 2MB Chip, 4MB Fast, SCSI (300+MB), SuperGen Genlock, Kick 3.1)
Back in my day, we didn\'t have water. We only had Oxygen and Hydrogen, and we\'d just have to shove them together.