English Amiga Board


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

 
 
Thread Tools
Old 13 July 2020, 20:39   #1
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 256
My simple Hello World gurus on exit

Hello all


I am well experienced in C but not on Amiga. I am using the VS Code extension for a convenient dev environment.


I am merely opening a window and waiting for the user to close it. When it exits I get a software failure. Any ideas why? Thanks so much! <3


Code:
#include "support/gcc8_c_support.h"
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <intuition/intuition.h>


struct ExecBase *SysBase;
struct DosLibrary *DOSBase;
struct IntuitionBase *IntuitionBase;

int main() {
    SysBase = *((struct ExecBase**)4UL);
    struct NewWindow NewWindow;
    struct Window *Window;

    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
    if (IntuitionBase == NULL)
    Exit(RETURN_ERROR);

    NewWindow.LeftEdge = 20;
    NewWindow.TopEdge = 20;
    NewWindow.Width = 300;
    NewWindow.Height = 100;
    NewWindow.DetailPen = 0;
    NewWindow.BlockPen = 1;
    NewWindow.Title = "DF0";
    NewWindow.Flags = SMART_REFRESH | ACTIVATE | WINDOWCLOSE | WINDOWDRAG;
    NewWindow.IDCMPFlags = CLOSEWINDOW;
    NewWindow.Type = WBENCHSCREEN;
    NewWindow.FirstGadget = NULL;
    NewWindow.CheckMark = NULL;
    NewWindow.Screen = NULL;
    NewWindow.BitMap = NULL;
    NewWindow.MinWidth = 0;
    NewWindow.MinHeight = 0;
    NewWindow.MaxWidth = 0;
    NewWindow.MaxHeight = 0;

    if ((Window = (structWindow *)OpenWindow(&NewWindow)) == NULL)
        Exit(RETURN_ERROR);

    Wait(1 << Window->UserPort->mp_SigBit);

    CloseWindow(Window);

    CloseLibrary(IntuitionBase);

    Exit(RETURN_OK);
}
Nightfox is offline  
Old 13 July 2020, 22:27   #2
kamelito
Zone Friend
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,285
it works fine without the last Exit(RETURN_OK); after closing intuitionbase, there's a missing space in that line but I guess it is a typo.
if ((Window = (structWindow *)OpenWindow(&NewWindow)) == NULL)
Exit(RETURN_ERROR);
kamelito is offline  
Old 13 July 2020, 23:22   #3
jotd
This cat is no more
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 49
Posts: 4,922
Which compiler are you using? if you're using gcc you should set -noixemul option
jotd is offline  
Old 14 July 2020, 05:13   #4
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 49
Posts: 569
I think you are not supposed to call Exit() but exit()
alkis is offline  
Old 14 July 2020, 13:30   #5
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 256
Quote:
Originally Posted by jotd View Post
Which compiler are you using? if you're using gcc you should set -noixemul option

The custom gcc that comes with the Visual Studio Code extension. Using that option in the makefile just gives me:
m68k-amiga-elf-gcc: error: unrecognized command-line option '-noixemul'


Quote:
Originally Posted by alkis View Post
I think you are not supposed to call Exit() but exit()

I have to call Exit because exit is undefined. Also Exit is used in the example code
Nightfox is offline  
Old 14 July 2020, 13:33   #6
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 256
Quote:
Originally Posted by kamelito View Post
it works fine without the last Exit(RETURN_OK); after closing intuitionbase, there's a missing space in that line but I guess it is a typo.
if ((Window = (structWindow *)OpenWindow(&NewWindow)) == NULL)
Exit(RETURN_ERROR);

Yes that was an error when copying and pasting the code into this forum post. The space isnt really there
Nightfox is offline  
Old 14 July 2020, 13:36   #7
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 49
Posts: 569
Quote:
Originally Posted by Nightfox View Post
I have to call Exit because exit is undefined. Also Exit is used in the example code
You shouldn't call Exit(), see http://amigadev.elowar.com/read/ADCD.../node015F.html

If the C compiler enviroment doesn't provide exit() then it is broken, as exit() is kind of fundamental.

Further more, when -- and only when -- you are inside main (as your sample is), you can replace exit(n); with return n;
alkis is offline  
Old 14 July 2020, 13:58   #8
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 559
Exit is part of dos.library, which you haven't opened. Adding

Code:
    DOSBase = (struct DOSBase *) OpenLibrary("dos.library", 0);
makes the crash go away.
deimos is offline  
Old 14 July 2020, 14:00   #9
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Perth, Australia
Posts: 256
Quote:
Originally Posted by alkis View Post
You shouldn't call Exit(), see http://amigadev.elowar.com/read/ADCD.../node015F.html

If the C compiler enviroment doesn't provide exit() then it is broken, as exit() is kind of fundamental.

Further more, when -- and only when -- you are inside main (as your sample is), you can replace exit(n); with return n;



Thanks, return 0 fixes the error. I normally use return n but I was following the example code that uses Exit(n) even in main().
Nightfox is offline  
Old 14 July 2020, 14:02   #10
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,344
Are you even linking to a c lib? Also where is the header file for exit()? stdlib.h
Hedeon 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
Any Octamed/MIDI gurus? marm support.Apps 25 25 September 2019 14:35
One for the Electronics Gurus... Please Charlie Hardware pics 3 04 July 2009 04:01
Getting a lot of gurus on A500! memothejanitor support.Apps 7 22 June 2007 22:30
My WinUAE HD GURUs at startup jjsmith22 support.WinUAE 7 09 April 2005 03:19
Scandoubler gurus needed. Desverger support.Hardware 7 05 August 2004 17:57

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 06:40.


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