Author Topic: GCC4TI string manipulation functions  (Read 6916 times)

0 Members and 1 Guest are viewing this topic.

Offline TC01

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 344
  • Rating: +9/-0
    • View Profile
Re: GCC4TI string manipulation functions
« Reply #15 on: July 25, 2010, 08:04:12 pm »
Unsigned char is a fine replacement for byte.

Does it really make a difference if I use unsigned char or unsigned int?

I mean, I know that unsigned char is the same size as a byte. It's just I already have the code written that treats the output as an array of integers.



The userbars in my sig are links embedded links.

And in addition to calculator (and Python!) stuff, I mod Civilization 4 (frequently with Python).

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: GCC4TI string manipulation functions
« Reply #16 on: July 25, 2010, 08:13:25 pm »
An array of integers? Don't you have to treat it as a byte (or unsigned char) array for it to have the same format as on the 83+ Series.
I mean, it could work, but that would make the files larger and the PC converter more complicated.
I wish you good luck with whatever avenue you take, though :)
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline TC01

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 344
  • Rating: +9/-0
    • View Profile
Re: GCC4TI string manipulation functions
« Reply #17 on: July 25, 2010, 11:05:28 pm »
...and now I have a memory leak. I know where it's coming but not how to fix it.

The tokenizePrgm() function (which is the core of my tokenizer code- it's essentially a main function called by the real main function in another file) creates a pointer to an array of NUM_TOKEN tokenInfo objects.

This array is passed to an initTokens() procedure, which builds tokenInfo objects based on data stored in three arrays (this will change, obviously, when I implement the token file). I dynamically allocate memory to the names of each of those tokens.

The tokens array is then passed to all functions that need to use it, and at the end, in tokenizePrgm() I free up the tokens array.

Unfortunately, I haven't freed up the memory I allocated to the tokenInfo.name part of each token. And if I try to do it by looping over each token and calling:

Code: [Select]
free(tokens[i].name);
I get an address error.

Is there any way I can free this memory, or is the only solution not to use dynamic memory allocation here?



The userbars in my sig are links embedded links.

And in addition to calculator (and Python!) stuff, I mod Civilization 4 (frequently with Python).

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: GCC4TI string manipulation functions
« Reply #18 on: July 26, 2010, 01:36:52 am »
Quote
Does it really make a difference if I use unsigned char or unsigned int?
Size and potentially padding: unsigned int is, with the default compiler settings, 16 bits, while unsigned char is 8 bits.
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.