Amiga-Development

Please login or register.

Login with username, password and session length
Advanced search  

News:

Created for developers of all Amiga camps

Author Topic: struct libbase or struct library  (Read 3797 times)

0 Members and 1 Guest are viewing this topic.

tolkien

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
struct libbase or struct library
« on: August 02, 2013, 01:51:23 PM »

Here I go again.

While learning MUI when I had to open mui library O had to do struct Library *muibase instead of the tipical struct libbase *libbase...
Why? Does It happends with other libraries?
I hope you understand cos my English is terrible and writing with a smartphone.

Thanks mates.
Logged

PeterK

  • Newbie
  • *
  • Gender: Male
  • Posts: 24
    • View Profile
Re: struct libbase or struct library
« Reply #1 on: August 02, 2013, 02:34:10 PM »

I'm really not a C-programmer, as I usually write ASM code, so my answer might be wrong, but I would say that "libbase" is NOT a structure, it's only something like a ULONG, pointing to a library structure. So, for me, it seems that struct library *muibase is correct or you could also try libbase *muibase. But again, I'm not an expert for C !!
« Last Edit: August 02, 2013, 02:36:11 PM by PeterK »
Logged
Projects: icon.library 46.4, IconBeFast, MemTrailer, TagLiFE, MathLibsUAE and MinStack

Team Chaos Leader

  • Administrator
  • Sr. Member
  • *****
  • Posts: 484
  • JC + Asm Coder
    • View Profile
Re: struct libbase or struct library
« Reply #2 on: August 02, 2013, 05:03:11 PM »

I always write
struct library * WhateverBase;

For all my libraries.  I open several libraries but not MUI.

But I think it works no matter how you write it.  But don't quote me on that cause its one of those mysteries that us mere mortals were never meant to understand.  :D
Logged

tolkien

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: struct libbase or struct library
« Reply #3 on: August 02, 2013, 08:22:13 PM »

Hiz PeterK. Here a fan of your icon.library.
Chaos,  Ill try using Library in a few libraries to see if change something. Im a nobb so sorry for these questions ant thanks.
Logged

magorium

  • Full Member
  • ***
  • Posts: 221
  • Programming is an art form that fights back
    • View Profile
Re: struct libbase or struct library
« Reply #4 on: August 03, 2013, 12:21:35 PM »

Here I go again.
Yippie !  ;D

But first of all c is also not my language, but i do come across it a lot (and rewrite).

Quote
While learning MUI when I had to open mui library O had to do struct Library *muibase
I find that hard to believe. One exception to that would be if you would use the standard defined muibase variable (which could be specifically typecasted/declared as such).

Quote
instead of the tipical struct libbase *libbase...
Are you sure about that ?
Because when i search for struct libbase in complete amiga sdk, it is non-existant.

Did you perhaps mean struct library *LibBase ?

Quote
Why? Does It happends with other libraries?
I hope you understand cos my English is terrible and writing with a smartphone.

A little explanation:

Every library you open with OpenLibrary returns a pointer to struct library. This means that whenever you open a library a pointer to this structure is returned.

This is because struct library is a common structure that every library _has_ to follow. The structure can be viewed here.

So, every opened library has the same set of default fields which is defined in this Library structure. They all have this structure _in common_.


But..., not all libraries are the same _after_ that defined library structure (and therefor its contained/defined fields).

For example, here you can see the structure of the Graphics library. The structure is called GfxBase.

As you can see, the first entry in that structure is called LibNode and is of type struct Library (the part that is common to all libraries and mentioned in earlier paragraph). If you look beyond that (first LibNode) field, then you can see all other kind of fields being defined (and that might be to interrest to you or your program).

Therefore it does not matter if you use struct library * libbase or struct GfxBase * when you open the graphics library. But when for example your program needs to acces one of the extended defined fields, you better cast your library base to struct GfxBase *.

You can decide yourself if you want to declare you own libbase variable for the library you openend and in what form you want it (being Struct Library* or Struct LibraryStructureName*, where librarystructurename is the library you openened (although not _all_ libraries have an extended library structure).

And there is always the possibility later on (in your code) to cast a Struct Library* into Struct LibraryStructureName* and vice versa).

Does that make sense somewhat, or did i perhaps misunderstood the question ?
Logged

tolkien

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: struct libbase or struct library
« Reply #5 on: August 03, 2013, 12:44:57 PM »

Hello Magorium!

Thanks...I have a few things to read now.

When I say LibBase I mean GfxBase for example.

In my compiler setup I cant do struct Library *IntuitionBase;
It must be struct IntuitionBase *IntuiBase;  Yes, I must typecast in OpenLibrary.

But extrangely with MUI the process is the contrary. But I need to practice more and read carefully what you have written.

Thanks for the info!
Logged

SamuraiCrow

  • Administrator
  • Sr. Member
  • *****
  • Gender: Male
  • Posts: 378
  • Coolness is compiled
    • View Profile
Re: struct libbase or struct library
« Reply #6 on: August 03, 2013, 08:55:28 PM »

The library bases all have struct Library at the beginning of them.  It is always legal to use struct Library *LibBase but seldom useful to do so (unless you are on OS4 but I digress).  The reason for this is they all have stuff after struct Library that would be unaccessible if you only accessed the Library structure.  IntuiBase, for example, has a lot of fields in its base structure that holds linked lists of struct Window and so on, to hold all the Windows that are valid in the system.  Be careful though, as of Workbench 3.5 you have to obtain a semaphore to lock the library base and release it when you are done because every multitasking program can access the contents of the library base.  I think this is done on Intuition.library but it might have been done on Graphics.library also.
Logged