Welcome, Guest. Please login or register.

Author Topic: Learning C with the Amiga  (Read 12350 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline lionstorm

Re: Learning C with the Amiga
« Reply #29 on: January 28, 2007, 05:38:14 PM »
Quote

Mad_Dog wrote:
Hi,

If you understand German, my C workshop may be the right place for you to start:

http://www.norman-interactive.com/C-Kurs.html


how about translating it to English ? That way it will profit to a much bigger andience (including myself).

Thanks
 

Offline Doraemon

  • Jr. Member
  • **
  • Join Date: Oct 2002
  • Posts: 87
    • Show only replies by Doraemon
Re: Learning C with the Amiga
« Reply #30 on: January 28, 2007, 07:00:24 PM »
And me  :-P
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Learning C with the Amiga
« Reply #31 on: January 28, 2007, 07:50:42 PM »
Quote
To make things a bit more complex: the above mechanism works only for programs you start from the CLI. For programs which start from the Workbench, you will need to use a different and much more Amiga-like mechanism. For now you can ignore its existence, but remember that you need to perform a bit of special processing if you want your program to be double-clickable.

Small correction: standard Amiga C startup code does handle WB startup just fine. Any output will open a console window. When started from an icon, argc is 0.
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #32 on: January 29, 2007, 02:23:01 PM »
Hi!

Wow so many ways to start a program in C! I think Ill stick with the basic "int main(int argc, char** argv)" one for now.
I love my MX5!
Please pay a visit
 

Offline CannonFodder

  • Hero Member
  • *****
  • Join Date: Sep 2003
  • Posts: 1115
    • Show only replies by CannonFodder
Re: Learning C with the Amiga
« Reply #33 on: January 29, 2007, 08:27:19 PM »
Quote

mel_zoom wrote:
Hi!

Wow so many ways to start a program in C! I think Ill stick with the basic "int main(int argc, char** argv)" one for now.


Basic?  Shh, you´ll wake the VB dragon. ;-)

int main(void) {} is the basic way anyhow. :-)
People are hostile to what they do not understand - Imam Ali ibn Abi Talib(AS)
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #34 on: February 03, 2007, 12:49:17 AM »
Hi!

I think Im actually making progress in the theory and I have just finished installing from the CD Karlos gave me. Fingers crossed I can actually compile something soon :-)
I love my MX5!
Please pay a visit
 

Offline Louis Dias

Re: Learning C with the Amiga
« Reply #35 on: February 03, 2007, 01:22:11 AM »
Quote

CannonFodder wrote:
Quote

mel_zoom wrote:
Hi!

Wow so many ways to start a program in C! I think Ill stick with the basic "int main(int argc, char** argv)" one for now.


Basic?  Shh, you´ll wake the VB dragon. ;-)

int main(void) {} is the basic way anyhow. :-)


The dragon has awaken.
However, it is a wise old dragon and know when trolls are trying to feed it poison and decides to go back to sleep.

Anyway, this method works just as well:

#include
#include
#include
void main()
{
char *Result;
int CannonFodder, funny;

funny = 1;
CannonFodder = 0;
Result = "";

if (CannonFodder != funny) Result = "not";
printf("Cannon Fodder is %s funny.\n",Result);
printf("Cannon Fodder is a %d\n",CannonFodder);
}


See what you get...
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Learning C with the Amiga
« Reply #36 on: February 03, 2007, 02:28:53 AM »
@lou_dias

No need to #include or .

Better to use "int main(void)", your main() doesn't specify anything whatsoever about arguments (C contrasts to C++ in regarding an empty parameter list as "no information given" rather than "no arguments"). Also, remember to return an integer, preferably 0 for success.

Never assign a string literal to a plain "char*" unless you really want to be able to modify its contents later, in which case the behaviour is undefined anyway (that is to say, modification of a string literal is undefined). Safer to use "const char*"

"if () ;" is bad style. Always surround the with braces, even when it is a single statement. A common source of error for beginners is to forget that the true branch of the "if" statement as you have written it ends at the first semicolon.

5/10: Could do better.
int p; // A
 

Offline AJCopland

Re: Learning C with the Amiga
« Reply #37 on: February 03, 2007, 11:33:26 AM »
@Karlos
 :roflmao:
Be Positive towards the Amiga community!
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #38 on: February 03, 2007, 06:44:32 PM »
lou_dias:

"See what you get..."

Well I could guess but I thought it might be interesting to see how it liked your definition of "main":

gcc -Wall test.c -o test
test.c:5: warning: return type of `main' is not `int'

Cannon Fodder is not funny.
Cannon Fodder is a 0

Im told that all good c programs are also c++ programs so I also tried in c++ mode and then it didnt compile at all.

g++ -Wall test.c -o test2
test.c:5: error: `main' must return `int'
test.c:5: error: return type for `main' changed to `int'

So according to that advice, this is not a good c program.

If you are planning to ridicule someone elses abilities shouldnt you do it in an "upwards compatible" way?
I love my MX5!
Please pay a visit
 

Offline Louis Dias

Re: Learning C with the Amiga
« Reply #39 on: February 03, 2007, 07:03:55 PM »
LOL @ all
:pint:

The topic is learning C not C++, anyway I wrote it from scratch and not on a compiler.

As I've mentioned before, I know enough C/C++ but don't use it at all at work and haven't tried in 10-12 years.

Ofcourse these "complaints" are my whole problem with the language as well as all the different standards.

It seems beginners fight more with the language than the actual art of programming.  Who does that help?  I understand it's place for core stuff like kernels and drivers, but for robust user applications, with today's processing power, I don't feel it's ideal.

Mel, may I recommend Hollywood 2.x to you.  It's one way to do Amiga programming and have it work on OS3, OS4 and AROS.  It's really an over-looked product.  It's as close to a ".Net" programming paradigm as you'll find in Amiga-land.
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #40 on: February 03, 2007, 07:47:53 PM »
lou_dias:

I never quit once I set my mind on something. I dont think the language looks that bad just yet!

This one worked fine....

#include

int main(void)
{
  const char *result;
  int lou_dias_joke;
  int backfired;

  lou_dias_joke = 1;
  backfired = 1;
  result = "was funny";
  if (lou_dias_joke == backfired) {
    result = "backfired";
  }
  printf("lou_dias joke %s.\n", result);
  return 0;
}

I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #41 on: February 03, 2007, 07:48:52 PM »
Mmm. Is there some way to keep the indentation when posting?
I love my MX5!
Please pay a visit
 

Offline Jupp3

  • Sr. Member
  • ****
  • Join Date: Mar 2002
  • Posts: 364
    • Show only replies by Jupp3
    • http://jupp3.amigafin.org
Re: Learning C with the Amiga
« Reply #42 on: February 03, 2007, 07:49:23 PM »
Quote
Ive decided to have a go at learning C on the amiga. I do know a little bit about the language and programming in general but Ive never really written anything.

That's a good idea. I also like the idea of starting to learn with C. Many people say they'll "start straight from C++" when many (including me) think that it's a good idea to learn the basics in C.

Of course that doesn't mean you would HAVE to move to C++, that's up to you. You can do in C everything, you can do in C++. And actually, I found C to suit my needs so well, that I never really thought of moving towards C++. I nowadays write C-code at work aswell.

At first it might be best to not go further than doing some simple shell programs (another thing you did right imho :-)), but then you should ask yourself what you want to do really?

Is it programs? Is it games? Is it something else?

And especially with games, you must decide what kind of games you would want to do. 3D (3D accelerated or not), 2D (system window or fullscreen, AGA or gfx-cards-only)

Personally I started using SDL and OpenGL. Both of them make many things so much easier. To be honest, I was surprised how easy it was to do simple 3D graphics with OpenGL. SDL is a bit more complex, but also makes many things (such as graphics, sounds, input handling etc.) much easier. Of course the bad news is that with both you can count out all <=AGA users but if you don't, you will be seriously restricting what you can do :-)

MorphOS has quite good SDL and OpenGL support, and I think OS4's support isn't probably all that bad either (currently there's no shared SDL library, and OpenGL isn't as "complete" as MorphOS equivalent, but it's just a matter of learning what functions to (not) use).Classic amiga version of SDL is not that good, but works. OpenGL, however, is about the same as currently on OS4, but obviously requires 3D card for any serious use (as it does on ANY system anyway)

Oh, did I mention that both SDL and OpenGL are available on many (mainstream and non-mainstream) platforms? :-)

If you are interested, I can paste links to some tutorials I found helpful.

Oh, and welcome here, I think I forgot to say that in the other thread :-)
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Learning C with the Amiga
« Reply #43 on: February 03, 2007, 08:06:29 PM »
Jupp3:

"You can do in C everything, you can do in C++"

I plan to learn c++ once I have a better understanding of c. At least I was told this was a good idea :)
I love my MX5!
Please pay a visit
 

Offline Louis Dias

Re: Learning C with the Amiga
« Reply #44 from previous page: February 03, 2007, 08:09:02 PM »
Quote

mel_zoom wrote:
lou_dias:

I never quit once I set my mind on something. I dont think the language looks that bad just yet!

This one worked fine....

#include

int main(void)
{
  const char *result;
  ...
  result = "was funny";
  ...
  result = "backfired";
  ...
}



ah yes, another thing about C syntax that makes no sense

"oh but the address stays the same" ... oh but it still leads to confusion because a variable declared as a constant should remain a constant, otherwise, why call it a constant?

const char result[] = "C is not fun";