Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmiWest Lesson 2"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
Line 60: Line 60:
 
== Static versus Dynamic Linking ==
 
== Static versus Dynamic Linking ==
   
  +
The different between static and dynamic linking can best be explained with an example.
Here is hello world done with static linking:
 
   
 
<syntaxhighlight>
 
<syntaxhighlight>
Line 72: Line 72:
 
</syntaxhighlight>
 
</syntaxhighlight>
   
  +
Here is "hello" created using static linking:
gcc -mcrt=clib2 -o hello hello.c
 
  +
  +
gcc -mcrt=clib2 -o hello hello.c -Wl,--cref,-M,-Map=hello.map
  +
  +
The "hello" executable is roughly 86906 bytes in size. The "hello.map" file contains the linker map which shows you exactly what pieces of code have been pulled in from where to create that executable.
  +
  +
Here is "hello" created using dynamic linking:
  +
  +
gcc -mcrt=newlib -o hello hello.c -Wl,--cref,-M,-Map=hello.map
   
 
== Libraries and Interfaces ==
 
== Libraries and Interfaces ==

Revision as of 04:14, 11 October 2012

AmiWest Lesson 2: Fundamentals

Basic Types

It is important to under at least the basic types when programming. The following table summarizes the basic types used in AmigaOS as compared to standard C and C++ types:

AmigaOS Types
Type Deprecated Type(s) C C++
uint64 none uint64_t uint64_t
int64 none int64_t int64_t
uint32 ULONG or LONGBITS or CPTR uint32_t uint32_t
int32 LONG int32_t int32_t
uint16 UWORD or WORDBITS or USHORT or UCOUNT or RPTR uint16_t uint16_t
int16 WORD or SHORT or COUNT int16_t int16_t
uint8 UBYTE or BYTEBITS char or unsigned char unsigned char
int8 BYTE signed char signed char
STRPTR none char* char*
CONST STRPTR n/a char* const x char* const x
CONST_STRPTR n/a const char* const char*
CONST CONST_STRPTR n/a const char* const const char* const
APTR none void* void*
CONST APTR none void* const x void* const x
CONST_APTR none const void* const void*
CONST CONST_APTR none const void* const const void* const
float32 FLOAT float float
float64 DOUBLE double double
BOOL none int16 int16
TEXT none char char
NULL none 0L (void*)0L
BPTR none int32_t int32_t
BSTR none int32_t int32_t
ZERO none (BPTR)0 (BPTR)0

Static versus Dynamic Linking

The different between static and dynamic linking can best be explained with an example.

#include <stdio.h>
 
int main()
{
 printf("Hello, world\n");
 return 0;
}

Here is "hello" created using static linking:

gcc -mcrt=clib2 -o hello hello.c -Wl,--cref,-M,-Map=hello.map

The "hello" executable is roughly 86906 bytes in size. The "hello.map" file contains the linker map which shows you exactly what pieces of code have been pulled in from where to create that executable.

Here is "hello" created using dynamic linking:

gcc -mcrt=newlib -o hello hello.c -Wl,--cref,-M,-Map=hello.map

Libraries and Interfaces

Shared Objects

Tasks and Processes

Code to display Tasks and Processes.

Synchronization Primitives