Click Here
home features news forums classifieds faqs links search
6095 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
22 crawler(s) on-line.
 95 guest(s) on-line.
 1 member(s) on-line.


 DC_Edge

You are an anonymous user.
Register Now!
 DC_Edge:  1 min ago
 FinnKersey:  12 mins ago
 Deaths_Head:  15 mins ago
 michalsc:  22 mins ago
 saimo:  29 mins ago
 amigakit:  44 mins ago
 clint:  46 mins ago
 NovaCoder:  1 hr 23 mins ago
 pixie:  1 hr 39 mins ago
 amigang:  2 hrs 14 mins ago

/  Forum Index
   /  Amiga Development
      /  I got c compiler warnings on Robert Pecks examples in his book
Register To Post

PosterThread
jonssonj 
I got c compiler warnings on Robert Pecks examples in his book
Posted on 9-Jul-2023 15:53:40
#1 ]
Regular Member
Joined: 1-Mar-2004
Posts: 299
From: Sweden, Bjärred

Hello!

I got the following compiler warnings when compiling an example from Robert Pecks book "Programmers guide to the Amiga"

dosio.c: warning 100 in dosio.c line 9: no prototype declared for function "Open"
dosio.c: warning 100 in dosio.c line 11: no prototype declared for function "Write"

the program looks like this:

''
#include "Iibraries/dosextens.h"
extern struct FileHandle *Open()
main( )
{
struct FileHandle *dos_fh;
dos_fh = Open("CON:10/10/500/150/New Window",
MODE_NEWFILE);
Write(dos_fh,"Helio world\n", 13);
Delay(300); /* delay 6 seconds */
Close(dos_fh);

}
''

What file do I need to include to get rid of the warnings? I have tried to search in the Rom Kernel manuals, but when i don't know what I'm looking for, it is like looking for a needle in a haystack, :)

I would be very happy for any kind of help with this.

BR
JJ

_________________
A1 X1000 is here !!!

 Status: Offline
Profile     Report this post  
OneTimer1 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 9-Jul-2023 17:31:37
#2 ]
Super Member
Joined: 3-Aug-2015
Posts: 1146
From: Germany

@jonssonj

[code]
Open("CON:10/10/500/150/New Window",MODE_NEWFILE);
[/code]

From page 17 ?

This seems to be one of the newer API functions introduced with AOS 2.04 maybe you are developing with a AOS 1.3 toolchain.

Maybe you should try this additional includes:

[code]
#include "exec/types. h"
#include "intuition/intuition.h"
#incl ude "intuitionlintuitionbase. h"
[/code]

 Status: Offline
Profile     Report this post  
jonssonj 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 9-Jul-2023 18:49:21
#3 ]
Regular Member
Joined: 1-Mar-2004
Posts: 299
From: Sweden, Bjärred

@OneTimer1

Thanks for your help, :) I really appreciate it, :)

I'm using the SAS / C 6.58 compiler/linker with the NDK 3.2R4

I tried your suggestion above, but I got the same warnings about "Open", "Write", "Delay" and "Close".

I guess that all of those instructions are in the same proto header file somewhere. I just can't find it.

EDIT: I forgot to mention that I use a real Amiga 1200 with Amiga OS 3.2.2

BR
JJ

Last edited by jonssonj on 09-Jul-2023 at 06:54 PM.

_________________
A1 X1000 is here !!!

 Status: Offline
Profile     Report this post  
NutsAboutAmiga 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 9-Jul-2023 20:48:20
#4 ]
Elite Member
Joined: 9-Jun-2004
Posts: 12960
From: Norway

@jonssonj

#include "proto/exec.h"
#include "proto/dos.h"


_________________
http://lifeofliveforit.blogspot.no/
Facebook::LiveForIt Software for AmigaOS

 Status: Offline
Profile     Report this post  
jonssonj 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 9-Jul-2023 21:42:46
#5 ]
Regular Member
Joined: 1-Mar-2004
Posts: 299
From: Sweden, Bjärred

@NutsAboutAmiga

Hello, Thanks for the help!

when adding those two lines I got new errors and warnings:

Error72 in dosio.c line 15: conflict with previous declaration; see line 44 file "include:clib/dos_protos.h"

Warning 100 in dosio.c line 20: no prototype declared for function "Open"

Warning 88 in dosio.c line 22: argument type incorrect;
Expecting "BPTR", found "struct FileHandle *"

Warning 88 in dosio.c line 24: argument type incorrect;
Expecting "BPTR", found "struct FileHandle *"


The third example in the book and it is impossible to get it to work,


_________________
A1 X1000 is here !!!

 Status: Offline
Profile     Report this post  
olsen 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 10-Jul-2023 6:13:08
#6 ]
Cult Member
Joined: 15-Aug-2004
Posts: 774
From: Germany

@jonssonj

Quote:

jonssonj wrote:
Hello!

I got the following compiler warnings when compiling an example from Robert Pecks book "Programmers guide to the Amiga"

dosio.c: warning 100 in dosio.c line 9: no prototype declared for function "Open"
dosio.c: warning 100 in dosio.c line 11: no prototype declared for function "Write"

the program looks like this:

''
#include "Iibraries/dosextens.h"
extern struct FileHandle *Open()
main( )
{
struct FileHandle *dos_fh;
dos_fh = Open("CON:10/10/500/150/New Window",
MODE_NEWFILE);
Write(dos_fh,"Helio world\n", 13);
Delay(300); /* delay 6 seconds */
Close(dos_fh);

}
''

What file do I need to include to get rid of the warnings? I have tried to search in the Rom Kernel manuals, but when i don't know what I'm looking for, it is like looking for a needle in a haystack, :)


Please keep in mind that the 'C' programming language evolved considerably since the days when these examples were written. You are looking at code which was written for the language as it was in 1978, described in the book "The 'C' programming language".

In order to get this to compile and link, and the compiler not complaining about something, you had to resort to declaring functions, with the important bit being the type of the result. Back in the day, there was no correct official collection of all Amiga library function declarations which could have been included in your program. Much later, you had such a "functions.h" file which shipped with the Manx Aztec 'C' compiler.

Here is how that code example would look like today, with NDK 3.2:

''
#include "proto/dos.h"

int
main(int argc, char **argv)
{
BPTR dos_fh;

dos_fh = Open("CON:10/10/500/150/New Window", MODE_NEWFILE);

Write(dos_fh,"Helio world\n", 13);

Delay(6 * TICKS_PER_SECOND); /* delay 6 seconds */

Close(dos_fh);

return 0;
}
''

The "proto/dos.h" header file, among other things, makes sure that the "dosextens.h" header file has been included, which in the original code still sat in the "libraries" directory. This takes care of the function prototype. We use "proto/dos.h" because the Open() function is found in dos.library, hence the name of that header file. For example, for exec.library you would use "proto/exec.h".

Note that the return type of the Open() function is not a 'C' pointer to a 'struct FileHandle'. Rob Peck wrote the code like this because the developer kit was not fully baked at the time (1986) and the workings of dos.library were largely poorly-documented.

That the Delay() function takes the number of ticks to wait is documented, but back in the day nobody seems to have used the covenient constant TICKS_PER_SECOND which is defined in the "dos/dos.h" header file (formerly known as "libraries/dos.h").

Last edited by olsen on 10-Jul-2023 at 07:53 AM.
Last edited by olsen on 10-Jul-2023 at 07:44 AM.
Last edited by olsen on 10-Jul-2023 at 07:25 AM.
Last edited by olsen on 10-Jul-2023 at 07:15 AM.
Last edited by olsen on 10-Jul-2023 at 06:13 AM.

 Status: Offline
Profile     Report this post  
jonssonj 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 10-Jul-2023 9:49:02
#7 ]
Regular Member
Joined: 1-Mar-2004
Posts: 299
From: Sweden, Bjärred

@olsen

Hello, Thanks for your help, I really appreciate it, :)

Yes, I know that the book is written many years ago, :), but there is'nt any books written for the latest way of programming the Amiga OS 3.x. It would be great if someone with the knowledge could rewrite all the examples in f.eg. the robert peck book. What I've heard Pecks book was one of the best out there.

Anyway, I will try your example and see if I can get it to compile without warnings and errors, and yet again, big thanks for your help! :)

_________________
A1 X1000 is here !!!

 Status: Offline
Profile     Report this post  
olsen 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 10-Jul-2023 11:15:47
#8 ]
Cult Member
Joined: 15-Aug-2004
Posts: 774
From: Germany

@jonssonj

Quote:

jonssonj wrote:
@olsen

Hello, Thanks for your help, I really appreciate it, :)

Yes, I know that the book is written many years ago, :)

Knowing that you have an extra hill to climb there (after which you realize it's just the foothills of a mountain range) is useful, but nobody should be spending too much time figuring out how to resolve the pitfalls resulting from the differences between the original K&R 'C' dialect and C90.

I had the questionable pleasure of learning all of this while it was still happening. You should not need to learn any of this just to get example code going. Amiga 'C' programming is already challenging, no need to make it even harder.

That said, I wish that the Rob Peck book had spent some time on doing proper error checking in the example code even if that would have distracted from the focus on showing concisely what needs to be done in order to print "Hello world!". The Amiga operating system performs little if any parameter validation and delegates that responsibility mostly to the developer. One lit match in that fireworks factory will ruin your day. And ever so slowly the curiousity which may have driven you will drain away. Rebooting your Amiga 500, from floppy disk, after you've again succeeded in crashing it, was punishingly slow in 1987.

Quote:
, but there is'nt any books written for the latest way of programming the Amiga OS 3.x.

Indeed, unless you count the changes made in recent NDK 3.2 AutoDoc revisions which paint in many of the blanks which existed since 1986. But this is reference documentation which assumes that you already know your way around the operating system and its features.

To the best of my knowledge, there is nothing equivalent to the Rob Peck book and similar publications of the same age. Even the "Classic AmigaOS Programming: An introduction" book is, content-wise, more a book of the Kickstart 1.x era than what followed it.

Somebody should write that book, spend several months, perhaps a year on it, and then publish it for free

Quote:

It would be great if someone with the knowledge could rewrite all the examples in f.eg. the robert peck book.

Oh well, I know a guy who could do this while sleepwalking --- but only while sleepwalking.

Last edited by olsen on 10-Jul-2023 at 11:17 AM.

 Status: Offline
Profile     Report this post  
jonssonj 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 10-Jul-2023 14:31:54
#9 ]
Regular Member
Joined: 1-Mar-2004
Posts: 299
From: Sweden, Bjärred

@olsen

who said it must be for free,

_________________
A1 X1000 is here !!!

 Status: Offline
Profile     Report this post  
x303 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 10-Jul-2023 22:16:46
#10 ]
Regular Member
Joined: 19-Jan-2005
Posts: 181
From: Amsterdam

@jonssonj

If the program works, but you only wanna get rid of the warnings, run scopts, goto 'message options' and set 'ignore 100'.

 Status: Offline
Profile     Report this post  
jonssonj 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 10-Jul-2023 23:08:23
#11 ]
Regular Member
Joined: 1-Mar-2004
Posts: 299
From: Sweden, Bjärred

@x303

Thanks for your input. I want to learn to write programs the "right way", not cheating, :)

BR
JJ

_________________
A1 X1000 is here !!!

 Status: Offline
Profile     Report this post  
bhabbott 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 14-Jul-2023 1:54:41
#12 ]
Cult Member
Joined: 6-Jun-2018
Posts: 509
From: Aotearoa

@jonssonj

Quote:

jonssonj wrote:

I want to learn to write programs the "right way", not cheating, :)

Good policy. Warnings should never be ignored unless you are sure they are benign and unavoidable, which is almost never so.

In this case the warning "Expecting "BPTR", found "struct FileHandle *"" is benign because the BPTR is stored in a longword and used as is. However a BPTR is actually an address divided by 4 to make a '32 bit word' address. If the program ever needed to convert this to a normal address you would be in trouble because it wouldn't know to do it.

BTW thanks for posting detailed information on the issues you are having. Things like this can be very frustrating for those of us who are not C experts (I code mostly in asm). I worked through your code with SASC 6.58 on my A1200 using KS3.1 includes just to get more experience dealing with problem like this. The spelling mistakes you put in the source code were also quite entertaining. :)

 Status: Offline
Profile     Report this post  
olsen 
Re: I got c compiler warnings on Robert Pecks examples in his book
Posted on 14-Jul-2023 8:47:31
#13 ]
Cult Member
Joined: 15-Aug-2004
Posts: 774
From: Germany

@bhabbott

Quote:

bhabbott wrote:
@jonssonj

Quote:

jonssonj wrote:

I want to learn to write programs the "right way", not cheating, :)

Good policy. Warnings should never be ignored unless you are sure they are benign and unavoidable, which is almost never so.

In this case the warning "Expecting "BPTR", found "struct FileHandle *"" is benign because the BPTR is stored in a longword and used as is. However a BPTR is actually an address divided by 4 to make a '32 bit word' address. If the program ever needed to convert this to a normal address you would be in trouble because it wouldn't know to do it.

Yes, in this case it works because there is no need for the code to have access to the underlying 'struct FileHandle' data structure members. Both Write() and Close() will do this "behind the scenes" for you.

The day may code (or it may never arrive) when you need to access what's behind the BPTR to a 'struct FileHandle' and then things will get "interesting".

In the mean time, removing the incorrect function declaration for Open() makes it safe to use the function prototypes provided with the more recent NDKs (starting with NDK 3.5). It saves trouble identifying a really puzzling problem as not so serious.

'C' error and warning messages got better over the decades, but older compilers still like to keep it brief and leave figuring out what the language "needs" to the developer. They used to say that 'C' was hard to get into and this is the first major hurdle anybody new to the language and its ecosystem will have to overcome

Sad fact: the original 'C' compiler featured much more humane and helpful error and warning messages, but this made it larger than it needed to be. So the part with the helpful and humane error and warning messages was sawn off so that the compiler could start and do its job much more quickly. What was sawn off became the "lint" command (sold separately) and the guys who had performed the operation were geniuses anyway and did not need that level of helpfulness in the compiler. "Helpful" sometimes means being able to get more work done using a more primitive tool.

Last edited by olsen on 14-Jul-2023 at 10:24 AM.

 Status: Offline
Profile     Report this post  

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle