Welcome, Guest. Please login or register.

Author Topic: Executing c command in c  (Read 2804 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show all replies
Re: Executing c command in c
« Reply #29 from previous page: June 02, 2017, 09:24:52 PM »
Apart from the mui specific stuff (Not sure if my question on getting items from a sorted list was missed or if nobody had an answer) my main problems have been strings. I'm used to languages where I don't have to worry about where they are in memory or remembering to have the end string characters. Now I have my head around those I'm getting the desired outputs and not getting any memory related errors.
It's nice to learn a different way of looking at them. I always knew they were arrays of characters but never thought too much about what the functions were actually doing.
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show all replies
Re: Executing c command in c
« Reply #30 on: June 03, 2017, 08:41:30 AM »
I think I might change from mui to reaction. I have more of an understanding of how things are working now.
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show all replies
Re: Executing c command in c
« Reply #31 on: June 08, 2017, 12:50:07 PM »
Well I got a lot further with my program and am now ready to.... start again.
1 of the ways I learn is by going back over what I have already done and trying to do it better, using all the things I've learned. As some of the stuff I did at the start is probably a mess and can be done better now I understand things more.
I do have a few questions though.

1 - I've come across the variables STRPTR and UBYTE *. Should I use these or char * . They don't appear to do much different to each other from the examples I've seen. I like the idea of using STRPTR as to me it makes it clearer what it is. UBYTE I don't like and I've only seen it in early coding examples?

2 - Is Allocmem() better than malloc()?

3 - I'm probably going to stick with MUI for the GUI but am interested to know what you guys would recommend using?

4 - Should I allocate and free memory for every string or just ones that will be shared between functions.

These may seem like questions that I should have asked about at the start but thats why I like to go back over things. So currently in my code I have different functions using various things I've picked up and now I want to make it more consistant .
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show all replies
Re: Executing c command in c
« Reply #32 on: June 09, 2017, 08:30:08 AM »
Thanks Thomas. Just a few follow ups based on your answers

1 -So for strings I think I'll stick with char * .I have UBYTE in a couple of areas of my code but that was from early stuff when I was reading some example code but from what you said I'm guessing that's not a good idea because I'm mixing 2 slightly different formats.

2 -With AllocMem() and malloc() my concern is that I read that you need to store certain things (images, sound) in chip memory and to do this you would use AllocMem and specify chipmem as one of the parameters. What I was reading implied that malloc would just use any available memory.

3 - Rather than what you recommend i guess I just meant what do you use which you answered. I like MUI probably because its the one I was looking at when everything clicked into how it worked. The only thing I don't like is that some things use hooks and I just can't get my head around how the hooks work. Not so much what is happening within the function but the calls to the hooks themselves. Where the parameters are coming from and how the return values work.

4 - Your string exampels were great. It's kind of what I was thinking but you made it clearer for me.
Kind of related to strings there is one other thing that I was reading that there seems to be a bit of a debate about on different sites and forums so I'd like to know what you think about...
When declaring pointers i've read people say that you shold set them to null or 0. Then when you have freed them you should set them back to null or 0.
Some people say this is a must while others say it isn't important and just causes extra work.

*edit* More  relating to the issue I have with hooks. For the mui lists DisplayHook in order to show only 1 column I'm using a hook which is modified from code I found.
So  I have

Code: [Select]
struct Hook disphook;
This I'm guessing is my hook

Code: [Select]
init_hook(&disphook, (HOOKFUNC)dispfunct, NULL); //call to init hook

void init_hook(struct Hook *hook, HOOKFUNC entry, APTR data)  // hook function
{
hook->h_Entry = (HOOKFUNC)HookEntry;
hook->h_SubEntry = (HOOKFUNC)entry;
hook->h_Data = (APTR)data;
}
I guess this is setting up the values in the hook structure. Though I'm not sure what HookEntry is or what data would be expected.
I'm also guessing that the 2nd patameter passed is the function that you would call

Code: [Select]
LONG dispfunct(struct Hook *hook, const char **array, struct ListItems *item)
{
if (rom)
array[0] = item->Name;
else
array[0] = "\033bName";
return(0);
}

and this is where I really get confused. I call this hook in the MUI List with MUIA_List_DisplayHook, &disphook .
How does it know what array and items are as I don't appear to pass anything to them??
« Last Edit: June 09, 2017, 09:24:03 AM by foleyjo »
 

Offline foleyjoTopic starter

  • Hero Member
  • *****
  • Join Date: Nov 2005
  • Posts: 608
    • Show all replies
Re: Executing c command in c
« Reply #33 on: June 09, 2017, 09:28:27 PM »
Thanks guys, you've given me a lot to work with and to consider.

This is a steep learning curve for me and once I want to say how great you have all been.

Things have slowed down for me now. Going over everything I've done and everything you have all said very carefully.
After all the advice I've been given I feel committed to get something finished and not let you feel you have wasted time helping me.