Welcome, Guest. Please login or register.

Author Topic: Odd programming question  (Read 6572 times)

Description:

0 Members and 1 Guest are viewing this topic.

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: Odd programming question
« Reply #14 on: March 09, 2008, 10:10:32 PM »
Sure all that is very interesting indeed, but I think it might be a bit too early for trekiej to delve into all that yet.

Granted, class explaining how to build your own OS from scratch could work even for beginners (as you then are not required to read and understand thousands of lines of existing code).
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #15 on: March 09, 2008, 10:38:13 PM »
There are some questions, though, that a beginning Amiga programmer might want to ask (I know I did):

What is amiga.lib, and when and why do I need it? What about my compiler's standard libraries?
What is auto.lib, and when and why do I need it?
Why does my console application exit before calling main?
Why does my compiler/linker come with more than one startup module? Which one do I use?

And it probably won't take long before a new programmer has to figure out why a seeminlgy innocent call to printf gurus.... For all their detail, the RKMs don't spend enough time discussing concurrency issues as they relate to the OS. Instead, they refer you to a standard work on operating systems, which, while relevant, won't take into account Amiga OS specifics. (EDIT: Of course, that's exactly what I did, too. ;-))

I think the OP will soon be back with some reasonable usage questions, too, e.g. what's the difference between printf and Printf?
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #16 on: March 09, 2008, 10:44:21 PM »
Is making a basic console program easy to do?
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #17 on: March 09, 2008, 10:46:15 PM »
Very:

/* hello.c */

#include

int main(int argc, char * argv[])
{
  printf("Hello, world!");
  return 0;
}

EDIT: That's C, of course. C++ came into its own after most compiler developers had left the Amiga behind.

What compiler are you using?
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #18 on: March 09, 2008, 10:55:28 PM »
For Amiga, nothing.  I am looking to use StormC.
GCC for linux.
AmiDevCPP for widows. (AROS)
Murks IDE
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline SamuraiCrow

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2281
  • Country: us
  • Gender: Male
    • Show only replies by SamuraiCrow
Re: Odd programming question
« Reply #19 on: March 09, 2008, 11:00:22 PM »
@trekiej

First of all, when a compiler compiles code, it goes directly to binary.  What the linker does is add bits of code that are functions supplied by the makers of the library being linked.

If you want something that doesn't care what operating system it uses when you compile it, you'll need one that has an intermediate representation of the code.  For the Mattathias Basic project, Sidewinder and I am working with Low-Level Virtual Machine.  It's bitcode will link to several different operating systems and processor code types.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #20 on: March 09, 2008, 11:04:29 PM »
@trekiej

AmiDevCPP has a toolchain for OS3, too.

@SamuraiCrow

Dude, way to add fuel to the fire. ;-)
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #21 on: March 09, 2008, 11:59:19 PM »
@Samurai Crow
Looks like you are working on something interesting.
Also, when the program gets changed to binary is there anything else the compiler does?

@Trev
Sure I knew that about AmiDev. :oops:
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #22 on: March 10, 2008, 01:52:29 AM »
Then you've got an Amiga environment ready to roll.

You're asking really basic compiler/linker questions, though. Try here: http://en.wikipedia.org/wiki/Linker.
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #23 on: March 10, 2008, 03:20:35 AM »
Thanks
Amiga 2000 Forever :)
Welcome to the Planar System.
 

Offline Trev

  • Hero Member
  • *****
  • Join Date: May 2003
  • Posts: 1550
  • Country: 00
    • Show only replies by Trev
Re: Odd programming question
« Reply #24 on: March 10, 2008, 03:56:48 AM »
And by basic, I didn't mean beginning. Compilers, linkers, loaders, etc. aren't usually the topics that people start with.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Odd programming question
« Reply #25 on: March 10, 2008, 10:58:50 AM »
Quote

trekiej wrote:
Outside of header files and libraries, when does OS specific information get added?
When I run a programm, how does  the OS allocate memory and give control to the application and the application give it back.
The OS gives the application access to resources, how does it know what to give?
Source > Object > linking > Binary


Your compiler implementation provides the standard C library (and maybe C++ library, etc too). The interfaces to these libraries, eg stdlib.h, stdio.h etc should provide the same set of functions across different platforms. They may vary depending on compiler age/version and even on platform but for example, stdio.h should provide you with the printf() function, for example, pretty much everywhere you go.

The implementation of these libraries, however is basically up to the compiler and the platform, as long as they provide the functionality advertised in the headers.

Your platform provides basic IO, memory management etc that the C library implementation for that platform uses. Essentially therefore, you can view your compiler's C standard library implementation as an abstraction layer to OS specific features.

When your code is linked, as well as the platform specific implementation of the C standard library, platform specific startup code is added that ensures your various IO streams etc. are available and ultimately invokes main() in your application.

Having said all this, you don't need to worry about any of it. As Piru stated, "It Just Works". How it works is really only of academic interest.
int p; // A
 

Offline Einstein

  • Sr. Member
  • ****
  • Join Date: Dec 2004
  • Posts: 402
    • Show only replies by Einstein
Re: Odd programming question
« Reply #26 on: March 10, 2008, 11:57:02 AM »
Quote

SamuraiCrow wrote:
@trekiej

First of all, when a compiler compiles code, it goes directly to binary.


I think it's not helpful to confuse beginners as they might wonder what the assemblers job then is.
I have spoken !
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #27 on: March 10, 2008, 06:42:07 PM »
Compiler, linker, assembler are not a problem.  It is how the OS looks at and responds to the program.  I wish I had a explanation of all that happens when a program loads.  This is imo different for different OS.
Amiga 2000 Forever :)
Welcome to the Planar System.
 

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: Odd programming question
« Reply #28 on: March 10, 2008, 06:48:30 PM »
Quote
It is how the OS looks at and responds to the program. I wish I had a explanation of all that happens when a program loads. This is imo different for different OS.

Even if it is, you don't need to worry about it. As long as you use the C standard library functions you will be just fine, regardless of the underlying OS.

That's the beaty of ANSI C, it's very very portable.
 

Offline trekiejTopic starter

Re: Odd programming question
« Reply #29 from previous page: March 10, 2008, 09:29:52 PM »
I appreciate all replies.

In the end I guess I will need to get into Kernel Dev to get the full understanding.

On a side note, do files have headers.  I do not mean xxx.h in a C program.  Is this not how an OS knows the difference between files?
@Karlos:
That is where I want to head with this.  I may get into Kernel Dev. with Linux but may go a non-programming route with my career.
Amiga 2000 Forever :)
Welcome to the Planar System.