English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. C/C++ (https://eab.abime.net/forumdisplay.php?f=118)
-   -   Help Learning (https://eab.abime.net/showthread.php?t=102011)

kfasheldon 29 April 2020 18:05

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 29 April 2020 19:13

The Code
 
1 Attachment(s)
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.

alkis 29 April 2020 19:58

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);
}


kfasheldon 29 April 2020 20:12

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 29 April 2020 21:18

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 !!

alkis 29 April 2020 22:37

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 29 April 2020 22:38

Also, it's a good amiga practise to ALWAYS CloseLibrary that you have opened with OpenLibrary.

kfasheldon 29 April 2020 23:12

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


All times are GMT +2. The time now is 19:14.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.04207 seconds with 11 queries