Welcome, Guest. Please login or register.

Author Topic: Wanted: General info/courses on C/C++  (Read 3884 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Wanted: General info/courses on C/C++
« on: October 28, 2006, 11:12:19 AM »
My one main() piece of advice would be:

If you haven't done any coding outside of BASIC/asm, forget about learning to write AmigaOS specific C/C++ code at the outset.

Not entirely, of course but I strongly advise learning the syntax of the language in an OS neutral way. Sure, that means writing a few no-fun "should compile anywhere" CLI programs to start with, but once you've mastered the basic syntax, anything you see in C for amigaos will make vastly more sense than they would otherwise.

As you've already done some ASM, you have an excellent background to understand C. This may sound a strange remark, but C is not as high level as many people would have you believe, which is one reason it tends to produce fast object code. A lot of concepts understood from assembler apply. In particular, pointers, which are often a source of confusion for people new to C are much more readily grasped as a concept when you already know about addressing modes like (a0), (a0)+, -(a0), (a0,d0.l*4) etc.

Before you even look at amigaos specific coding, you should be fully comfortable with functions, pointers, pointer casts (totally evil but essential for dealing with a lot of OS resources) and structures.

As you have worked with PHP, at least the brace syntax should be OK, as should be the notion of functions. A lot of people with experience only in basic struggle with C's universal function syntax which does not have a syntactical distinction between 'subroutines' and 'procedures'. A function may take parameters and either returns a value (procedure), or it doesn't (subroutine).
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Wanted: General info/courses on C/C++
« Reply #1 on: October 29, 2006, 10:52:54 AM »
Quote

SamuraiCrow wrote:

The biggest problem you'll run into is that most Amiga software is written in ANSI C but most of the tutorials today are based on C++.  There may be functionality missing on Storm C++ since it preceeded the ratification of the ANSI standards of C++.


If you get hold of StormC4, at least it's got a gcc 2.95.3 backend, so it tends to reasonably compile most stuff. However, it doesn't come with the C++ STL, though it is possible to kludge it in.

The main reason I'd reccommend StormC (any version) to a beginner is the IDE which really is very friendly (for more advanced projects it can rapidly become awkward, but by then you'll be on proper gcc/make ;-))

Quote

I don't use C++ unless I see a specific advantage to it since most of the stuff I do is either available in C or can be performed in object oriented code written in C (with a few function pointers here and there :-D ).


I've sort of gone past the point where I can stomach normal C code for most projects. I very rarely use it anymore, simply because the OOP paradigm is firmly entrenched in my noggin.

However, I agree you should use the right tools for the job. C is well suited for simple, OS native programs with not many source files.

The moment you find yourself making a lot of structures and functions to deal with them, you really ought to consider if C++ is the way to go.
int p; // A