Welcome, Guest. Please login or register.

Author Topic: C - Menus and multiple selections...  (Read 8215 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Thomas

Re: C - Menus and multiple selections...
« on: April 12, 2023, 08:04:20 AM »
DICE is giving me an "int-ptr conversion" warning on this line:
struct MenuItem* item = ItemAddress(&my_menu, code);

Probably because it is. You should #include <proto/intuition.h> to let dcc know about the return type of the ItemAddress function.

Also put -proto on the dcc command line to get an error for each undeclared function.


Offline Thomas

Re: C - Menus and multiple selections...
« Reply #1 on: April 12, 2023, 07:30:21 PM »
Thanx, I haven't looked into prototyping yet...

There is not much to look into. A prototype is just a repetition of the function declaration.

For example if this is your main program:

Code: [Select]
#include <stdio.h>

int main (int argc,char **argv)
{
printf ("Hello World\n");
return (0);
}

Then this is its prototype:

Code: [Select]
int main (int argc,char **argv);

You can make it shorter if you omit the argument names because for a prototype the compiler only needs the types, not the names.

Code: [Select]
int main (int,char **);

But it is much more readable with the names included, especially if there are multiple arguments of the same type.

And no, it does not ask for trouble, it helps you to avoid trouble.
« Last Edit: April 12, 2023, 07:34:07 PM by Thomas »
 

Offline Thomas

Re: C - Menus and multiple selections...
« Reply #2 on: April 14, 2023, 02:57:37 PM »
Maybe the 1.3 includes don't like the proto/intuition.h that came with DICE

Yes, you have to use a consistent set of include files. Have a look at https://eab.abime.net/showthread.php?t=68332, it instructs how to install Dice C correctly with the OS 3.9 NDK.

You can use the 3.9 NDK to write programs for 1.3 without issues. Just don't use functions which don't exist in OS 1.3.


Quote
(I looked at that .h file and it was pretty empty mostly pointing to other files, and as I don't fully understand prototyping and pragmas... ;-)   (obviously)

The proto/*.h files don't contain prototypes. They are (more or less) compiler-independent covers which include the necessary files to tell the compiler how to call OS functions in an efficient way.

The actual prototypes are in clib/*_protos.h

Pragmas tell the compiler how to populate registers with arguments. You might have heard that the OS expects arguments in registers while the C compiler usually puts them on the stack. The pragma instructions tell the compiler to use registers instead. But the #pragma syntax is compiler-specific, so it is not a good idea to include pragma/*.h files in your code. Rather use the proto/*.h file which should know which pragma files to use for each compiler.

It is rather safe to include clib/*.h instead of proto/*.h. It just creates a little overhead in each function call, because it first calls a C stub function which takes arguments from the stack and puts them in registers before it calls the actual OS function.

With the Dice C compiler you might run into situaitions when it tells you "subroutine is too complex to generate code for". In this case the simple solution is to use clib/ include instead of proto/.