Welcome, Guest. Please login or register.

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

Description:

0 Members and 1 Guest are viewing this topic.

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #14 from previous page: February 07, 2007, 08:58:24 PM »
samuraicrow:

"AFAIK structures cannot be passed by value and must be passed by reference"

Well, I was looking at this already and have written a test program that works. Did I compile this wrong?

gcc -Wall testbyval.c -o testbyval


The code is

/* test passing structures by value - why does this work? */

#include

struct coord {
  int x;
  int y;
};

struct coord testbyvalue(struct coord o)
{
  o.x++;
  o.y++;
  return o;
}

int main(void)
{
  struct coord c1 = {1,2};
  struct coord c2 = testbyvalue(c1);
  printf("c1 = {%d,%d}\nc2 = {%d,%d}\n}", c1.x, c1.y, c2.x, c2.y);
  return 0;
}

I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #15 on: February 07, 2007, 09:01:30 PM »
hans:

I understand that and I can see why arrays are "by reference" but why are structures allowed to be by value? Especially as they can contain an array even?
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #16 on: February 08, 2007, 05:49:23 PM »
lou_dias:

"We are way off topic for Mel."

Yes, it seemed to start with talk of ".net" :-P

"Here we have a new student to programming and you give her the loaded gun right away. That can/will lead to frustration. Bad descision. What is her "need" to learn C? Certainly, other languages could speed up her "learning to program" process. Learning these other languages could then speed up her subsequent "Learning To Program In C" process."

So far the only frustration is the language-war sideshow ;-) Im not finding C itself particularly difficult to comprehend for now. Why should I learn something else in order to qualify for learning C?

I dont mind the C++ chatter though I dont plan on looking into that for some time yet.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #17 on: February 08, 2007, 08:42:40 PM »
lou_dias:

"It's these quirks that make it not a good language for beginners. Maybe if she ever learns a second language (C++ doesn't count), then she'll see the light at the end of the tunnel."

Hmmm.

You seem to think that I am lost in a dark tunnel. Im not - C seems quite straightforward so far. Whats this "light" am I supposed to C? :-P

" C is a language with few rules. How do you write structured code when the language has no uniform structure within it's design. "

It seems quite structured to me. So far I have learned:

C provides very simple "types" that correspond to those typically used by the CPU directly. Anything more complicated requires you to define a structure that is composed of these types (and maybe other structures). I can already see how this provides a good "building up" principle for dealing with data in a program.

C code is structured into blocks that you surround in braces. Any variables you define inside a block can only be seen in that block and any blocks inside it and so on.

The highest level block of code is a function. You cant just write code anywhere. Therefore (unless I got this very wrong) all code in C lives only in functions wether they are built into a library or you have written them yourself.

The first function in your program is main(). This is what the system calls when your program is run and the value returned goes back to the system as an indicator of what happened. It was quite interesting to see what happened when I returned 5, 10 and so on and checked the shell's return code - you can actually see it.

My first program that used the full "main()" definition was this:

/* set the returncode for the amiga shell */

#include
#include

int main(int argn, char** argv)
{
  int r = 0;
  if (argn>1) {
    r = atoi(argv[1]);
  }
  printf("Setting return code to %d...\n",r);
  return r;
}

Ok, it isnt exactly the most useful thing but you can actually see how the shell and program interact which I thought was educational :-)

C is not very "wordy" and relies more on an equation-like written form. Which is good as far as Im concerned as it is easier to see at a glance what a block of code does when it isnt cluttered up with lots of keywords that distract you from what the code itself is actually is saying.


"C is a language designed for low-memory machines because that's all they had when it was designed. All these "quirks" are just hacks someone added to the compiler at the time because of memory constraints and over time "became part of the language". C is a hack to not have to write assembly."

According to the K&R book C was created for and on unix systems. I dont think they were regarded as "low-memory" in their day - after all the compiler itself uses quite a lot just to compile a program!

All the "low-memory" systems (home computers typically) I can remember from childhood used BASIC of some sort or other.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #18 on: February 09, 2007, 07:28:03 PM »
Hyperspeed:

"Mel: Are you Karlos' secretary?"

No. Is that the only IT role you can imagine a woman working in?

"Why does your Mazda link take me to a mammogram page?"

It isnt a Mazda link, its a link to a page that generates advertising money from your visits that in turn is used to provide free mammograms for those less well off. There are several other good causes on the same site that you can click on too.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #19 on: February 12, 2007, 12:19:21 PM »
lol!

Are you guys trying to put me off?
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #20 on: February 12, 2007, 01:07:12 PM »
I find it amusing that there is a vb.net versus C debate going on here when the whole point of the thread was specifically about learning C on the amiga :-)

First of all I want to learn C (with the aim of learning C++) and not VB. Second I wanted to use my amiga to learn it. Since no .net language is available on the amiga its irrelavent really.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #21 on: February 12, 2007, 01:21:42 PM »
cymric:

I may be a beginner but I do understand that C is low level. Im not about to give up if I run into a problem handling an array.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #22 on: February 13, 2007, 09:16:30 PM »
cannonfodder:

Perhaps he is trying to tempt me into VB coding :-)
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #23 on: February 13, 2007, 09:31:14 PM »
Nobody seems to get this. Im learning for my own interests, to be better qualified to deal with some of the technical jibber jabber I come across in my work and most of all - for fun!

A lot of SQL is used where I currently work - several implementations used across a range of systems. The one thing they all have in common is that they are overwhelmingly boring!
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #24 on: February 13, 2007, 09:37:40 PM »
If you must. I am thinking I will have to start a new thread if I want to ask questions about C coding. This one seems to have gone off all by itself :lol:
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #25 on: February 13, 2007, 09:47:49 PM »
Well. Nothing amiga specific yet. Just the K&R book - for reference and a self paced book called "mastering standard C". Of course there is also a lot of resources on the web.

Perhaps I can use certain culinary skills to lure a personal C tutor that happens to be fond of spicy food... Except he seems to have vanished under a landslide of work ;-)
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #26 on: February 23, 2007, 01:30:55 PM »
NattyBoh:

"Be careful Melanie, Karlos is a Muslim, for sure he will beat you and force you to wear the burka."

So you said in my welcome thread. Ill be sure to be extra careful :roll:

Sounds almost as much fun as going to your wonderful country to enjoy a nice traditional pharonic circumcision.
I love my MX5!
Please pay a visit
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show all replies
Re: Learning C with the Amiga
« Reply #27 on: February 23, 2007, 02:01:46 PM »
I noticed you changed your last post. You had said something like: "You realise he'll expect you to put out"

Put what out?

English might not be my first language but Im sure you arent using it properly.
I love my MX5!
Please pay a visit