English Amiga Board


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

 
 
Thread Tools
Old 18 December 2017, 20:59   #1
jagLally
Registered User
 
Join Date: Dec 2017
Location: London
Posts: 51
vbcc warning assignment of different pointers

hopefully this is a basic question but google search for last few hours isn't yielding anything meaningful.

I'm new to C as I haven't touched it for over 20 years and even then it wasn't hard core. But I am a programmer. I keep getting a warning from vbcc compiler and I'm scratching my head.
Code:
/Users/jaglally/amigaDev/vbcc/bin/vc +kick13 -c99  -I/Users/jaglally/amigaDev/NDK_3.9/Include/include_h IntuitionWindow.c -lamiga -lauto -o intuitionWindow2
>    windowPtr = OpenMyNewWindow(IntuitionBase);
warning 85 in line 62 of "IntuitionWindow.c": assignment of different pointers
This is very basic experimentation for me as I'm just starting out, but I want to understand why. I've tried explicit cast but warning stays. It runs fine in emulator FS-UAE.

Code:
//
//  IntuitiionWindow2.c
//

#include <exec/types.h>
#include <intuition/intuition.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <stdlib.h>
#include <stdio.h>
#include <proto/dos.h>

#define INTUITION_REV 0

struct Window * OpenMyNewWindow(struct IntuitionBase *IntuitionBase)
{
    
    printf("OpenMyNewWindow. IntuitionBase passed just for the hell of it %p \n",(void *)IntuitionBase);
    // structure of type NewWindow also called NewWindow.
    struct NewWindow newWindowDef;
    // pointer to structure of type Window.
    struct Window *windowPtr = NULL;
    
    newWindowDef.LeftEdge = 20;
    newWindowDef.TopEdge = 20;
    newWindowDef.Width = 300;
    newWindowDef.Height = 100;
    newWindowDef.DetailPen = 0;
    newWindowDef.BlockPen = 1;
    newWindowDef.Title = "A Simple Window 5";
    newWindowDef.Flags = WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
    WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | NOCAREREFRESH;
    newWindowDef.IDCMPFlags = CLOSEWINDOW;
    newWindowDef.Type = WBENCHSCREEN;
    newWindowDef.FirstGadget = NULL;
    newWindowDef.CheckMark = NULL;
    newWindowDef.Screen = NULL;
    newWindowDef.BitMap = NULL;
    newWindowDef.MinWidth = 0;
    newWindowDef.MinHeight = 0;
    newWindowDef.MaxWidth = 600;
    newWindowDef.MaxHeight = 400;
    
    // call OpenWindow with address of structure definition. returns a pointer.
    windowPtr = OpenWindow(&newWindowDef);
    return windowPtr;
}

int main(int argc, char **argv)
{
    // structure of type library pointer call IntuitionBase
    struct IntuitionBase *IntuitionBase = NULL;
    
    struct Window *windowPtr = NULL;
    
    // function declared to return a general library pointer. opening Intuition returns
    // IntuitionBase which has extra data
    IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", INTUITION_REV);
    if (IntuitionBase == NULL) exit(FALSE);
    printf("Intuition library opened. base address %p \n",(void *)IntuitionBase);
    
    windowPtr = OpenMyNewWindow(IntuitionBase);
    if ( windowPtr == NULL) {
        printf("holy crap. OpenMyNewWindow did not work\n");
        exit(FALSE);
    }
    Wait(1 << windowPtr->UserPort->mp_SigBit);
    CloseWindow(windowPtr);
    CloseLibrary((struct Library *) IntuitionBase);
    return 0;
}
jagLally is offline  
Old 18 December 2017, 21:45   #2
jagLally
Registered User
 
Join Date: Dec 2017
Location: London
Posts: 51
I can't believe I sort of figured it out within 40 minutes of posting after spending hours. I needed to tidy up my includes to

Code:
#include <stdio.h>
#include <stdlib.h>
#include <exec/types.h>
#include <intuition/intuition.h>
//#include <clib/exec_protos.h>
//#include <clib/intuition_protos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/dos.h>
All warning gone. My next lesson is look into what these clib header files are. Can't recall which example code I picked them up from.
jagLally is offline  
Old 18 December 2017, 23:58   #3
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by jagLally View Post
My next lesson is look into what these clib header files are. Can't recall which example code I picked them up from.
You should always use <proto/xyz.h> for including a library's prototypes. It also includes <clib/xyz_protos.h>, but additionally it declares the library base (IntuitionBase in this case) and includes some compiler-specific stuff to call library functions directly, without calling a stub function from amiga.lib first.

The problem here was that "struct IntuitionBase" was completely unknown. And, admitted, the error message was misleading.

You can reproduce that with a simple test (here "struct xyz" is unknown):
Code:
void f(struct xyz *x)
{
        x = 0;
}

int main()
{
        struct xyz *tst = 0;

        f(tst);
        return 0;
}
Compiling it yields the same warning:
Code:
frank@tethys vc +aos68k tst.c
>       f(tst);
warning 85 in line 10 of "tst.c": assignment of different pointers
phx is offline  
Old 19 December 2017, 00:39   #4
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
not an expert, but take a look at the answers by Thomas.

#1) I should reload the page, before I answer, just missed the replys aleady given

Last edited by emufan; 19 December 2017 at 00:59.
emufan is offline  
Old 19 December 2017, 20:16   #5
jagLally
Registered User
 
Join Date: Dec 2017
Location: London
Posts: 51
Thanks both of you. It was a big help in understanding. I sort of managed to follow the include logic and see what you said. The linked post also helped.

I also see that vbcc also has clib with protos as part of targets. E.g. m68k-kick13. Would you know the reason why someone would choose these over the NDK ones or when to choose one over the other?
jagLally is offline  
Old 21 December 2017, 14:42   #6
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Last time I checked all the official AmigaOS 3.x SDKs did not include a proto directory, only clib. proto is compiler specific and should be provided with the compiler (or the compiler's target files).

"clib" only contains simple C prototypes, and requires you to link your code with stub functions from amiga.lib, which do the actual OS-calls from these stubs.

All modern Amiga compilers also support direct OS calls, elimintating the overhead of calling such a stub function. But that's done with compiler-specific extensions, which are not part of the official C standard (like assembler inlines, or pragmas). Therefore you want to include <proto/...>.
phx is offline  
Old 21 December 2017, 14:59   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Aarrrgh! Sorry. I misunderstood your question. Ignore my previous posting!

Quote:
Originally Posted by jagLally View Post
I also see that vbcc also has clib with protos as part of targets.
Yes. The m68k-kick13 target (and only this!) includes clib files, because the official Commodore 1.3 SDK didn't have them. Without those you would have no prototypes at all, which would cause lots of warnings with a C99 compiler. And I wanted to stay compatible with fd2pragma, which generates proto-files including clib.

EDIT: Do not use m68k-kick13 with a 3.x SDK! Otherwise you are calling for trouble. m68k-kick13 is designed to be used with the original 1.3 SDK from the 80s.

Last edited by phx; 21 December 2017 at 15:07. Reason: 1.3 SDK
phx is offline  
Old 03 January 2018, 20:24   #8
cla
dev
 
cla's Avatar
 
Join Date: Aug 2014
Location: Copenhagen
Age: 48
Posts: 65
Send a message via ICQ to cla
Quote:
Originally Posted by jagLally View Post
Thanks both of you. It was a big help in understanding. I sort of managed to follow the include logic and see what you said. The linked post also helped.

I also see that vbcc also has clib with protos as part of targets. E.g. m68k-kick13. Would you know the reason why someone would choose these over the NDK ones or when to choose one over the other?
Elaborating on the above: The libraries in OS1.3 (Kickstart 1.3) does not supply the same library functions as 3.1 or 3.9. Hence they need they own headers.
cla 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
Looking for Cool Pointers squidbass Amiga scene 2 27 March 2015 12:12
Arcade: Joystick Assignment Issue. Jason H support.FS-UAE 1 31 March 2014 23:07
2 Mouse Pointers!!! wandeep support.WinUAE 3 21 May 2008 13:44
Two mouse pointers! mlft support.WinUAE 16 21 December 2002 02:52

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 18:05.

Top

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