English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 29 April 2020, 18:05   #1
kfasheldon
Registered User
 
Join Date: Oct 2006
Location: Ottawa, Canada
Posts: 50
Help Learning

Hi ,

I have just set up a WinUAE with HiSiftC 4 and SAS/C 6.58.
I have 'Amiga C for Beginners' and a few other Amiga and C reference books.
Very basic understanding of 'C' but no experience.

So I decided to type in the example Window program on page 231 of the Abacus Amiga C for Beginners using GoldEd which nicely recognized SAS/C and compiled the Hello World example fine.

Bur when I go to compile the window example it tells me the OpenLibary and exit functions are not dfined.

Trying HiSoftC and setting it to ANSI C not C++ I get similar sets of errors.

Most Puzzled as its not the most exotic of programs and quite clear as to what it is doing.

Looking at the SAS/C example 'lines' this has a completely different looking code to open windows and by using the includes from this and stripping the INTUITION_REV stuff from the Abacus code and the exit lines I can get it to compile and provide a window but of course no way to close it.

Please can someone advise as to what to set up so that the example code works , searching the net points to some setup code required by SAS/C using Pragma ? , as for HiSoftC I have no idea.

Thanks
kfasheldon is offline  
Old 29 April 2020, 19:13   #2
kfasheldon
Registered User
 
Join Date: Oct 2006
Location: Ottawa, Canada
Posts: 50
The Code

This is the file as typed in.

HiSoft C complains;

No prototype defined for function exit in line 19
assignment type conflict in line 40
no prototype defined for function CloseWindown in line 48
no prototype defined for function CloseLIbrary in line 49

Why?

SAS/C also complains that OpenLibrary is not a defined function then the above errors ?

Cant for the life of me work this out as all looks correct.
Attached Files
File Type: c Test.c (1.1 KB, 55 views)
kfasheldon is offline  
Old 29 April 2020, 19:58   #3
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 50
Posts: 580
Don't know about hisoftC but sas has the system's library calls defined in proto/ folder in includes.

So, if you want to use Exec's OpenLibrary, CloseLibrary etc you
#include <proto/exec.h>

If you want to use Intuition's OpenWindow, CloseWindow you
#include <proto/intuition.h>

Also, if you want to wait for some time, you can use Dos' Delay and you
#include <proto/dos.h>

So, here is the altered source with some notes within. Tested with SasC.
Code:
#include <exec/types.h>
#include <intuition/intuition.h>

#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>

/* These are defined in proto/intuition.h  and proto/exec.h*/
/*
extern struct window *OpenWindow();
extern long *OpenLibrary();
*/
struct IntuitionBase *IntuitionBase;

#define INTUITION_REV 0

main()
{
	struct NewWindow NewWindow;
	struct Window *Window;
	long i ;

	IntuitionBase = ( struct IntuitionBase * ) OpenLibrary( "intuition.library" , INTUITION_REV );

	if ( IntuitionBase == NULL )  
		exit ( FALSE ) ; 

	NewWindow.LeftEdge	=20;
	NewWindow.TopEdge	=20;
	NewWindow.Width		=200;
	NewWindow.Height		=80;
	NewWindow.DetailPen	=0;
	NewWindow.BlockPen	=0;
	NewWindow.IDCMPFlags	= NULL;
	NewWindow.Flags		= SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | NOCAREREFRESH;
	NewWindow.FirstGadget = NULL;
	NewWindow.CheckMark	=  NULL;
	NewWindow.Title		= (UBYTE *)"The User Window";
	NewWindow.Screen		= NULL;
	NewWindow.BitMap		= NULL;
	NewWindow.MinWidth 	=80;
	NewWindow.MinHeight	=25;
	NewWindow.MaxWidth	=640;
	NewWindow.MaxHeight	=200;
	NewWindow.Type		=WBENCHSCREEN; 

	if (( Window = OpenWindow (&NewWindow)) == NULL) 
	 exit (FALSE);
	/* If we exit above, we leave intuition library open */

	/* horrible busy wait loop */
	/* Also with typo 1<800000 makes it infinite*/
	/* Probably meant as i<800000 */
	/*for(i =0; 1<800000; i++);*/

	/* let's just wait properly for 10 secs */
	Delay(50*10);
	
	CloseWindow (Window);
	CloseLibrary (IntuitionBase);
	exit (TRUE);
}
alkis is offline  
Old 29 April 2020, 20:12   #4
kfasheldon
Registered User
 
Join Date: Oct 2006
Location: Ottawa, Canada
Posts: 50
Many Thanks, I guess the book is older as SAS/C is not quite the same as Lattice or Aztec original versions, proto clearly defines the common structures in place of having to add yourself I guess.
kfasheldon is offline  
Old 29 April 2020, 21:18   #5
kfasheldon
Registered User
 
Join Date: Oct 2006
Location: Ottawa, Canada
Posts: 50
Ok had to replace exit with return , solved that and works for this program. exit seems to to exist at all. Then CloseLibrary (IntuitionBase); claims it is an invalid argument ?

removing that line and it work !!
kfasheldon is offline  
Old 29 April 2020, 22:37   #6
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 50
Posts: 580
exit was misused, doesn't make any sense to use it inside the main() function. You probably saw the warning which you can solve with #include <stdlib.h>

CloseLibrary gives another warning and that can be solved with casting, like:
CloseLibrary((struct Library *) IntuitionBase);

Take note that the above are both _warnings_. Not errors.
alkis is offline  
Old 29 April 2020, 22:38   #7
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 50
Posts: 580
Also, it's a good amiga practise to ALWAYS CloseLibrary that you have opened with OpenLibrary.
alkis is offline  
Old 29 April 2020, 23:12   #8
kfasheldon
Registered User
 
Join Date: Oct 2006
Location: Ottawa, Canada
Posts: 50
thank you, I have managed to find a way to close the Intuition library in some online code that placed void CloseLibrary before main and this seams to work fine.

And reading online I also found that exit could be resolved by including stdlib but return was referenced as being the better way
.. casting the close makes sense as it is the opposite of the cast to open it.

Thanks once again
kfasheldon is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
help learning asm, needed ?? turrican3 Coders. Asm / Hardware 53 21 August 2019 19:36
Learning C nobody Coders. C/C++ 28 15 June 2016 08:07
I need help with my intro... I´m learning... Skillion76 Coders. General 10 27 September 2014 17:36
Suggestions for learning pmc Coders. Tutorials 248 20 October 2010 21:42
Learning assembler bLAZER Coders. General 1 12 May 2007 05:00

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:08.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.11068 seconds with 16 queries