delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/11/11:14:32

Message-ID: <37AF96DC.4B20@ns.sympatico.ca>
From: Klaas <klaas AT ns DOT sympatico DOT ca>
Organization: N/A
X-Mailer: Mozilla 3.04 (Win95; I)
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How do I set up predefined structures?
References: <7oo1aa$cmh$1 AT news7 DOT svr DOT pol DOT co DOT uk>
Lines: 85
Date: Tue, 10 Aug 1999 00:05:00 -0300
NNTP-Posting-Host: 142.177.75.52
X-Trace: sapphire.mtt.net 934254273 142.177.75.52 (Tue, 10 Aug 1999 00:04:33 ADT)
NNTP-Posting-Date: Tue, 10 Aug 1999 00:04:33 ADT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Andrew Davidson wrote:
> 
> I'm trying to set up a set of predefined structures for a C based emulator
> I'm writing using GCC and Allegro. It's intended to allow easy definitions
> of ROM loading information and the overall description of each of the ROM
> sub-sets (there are 3 sub-sets in every game: program, tile, and sprite) is
> NULL terminated because it can vary in length:
> 
> These make up the basic structures:
> 
> typedef struct rom_double {
>     char *file1,*file2;
>     int length;
> }
> 
> typedef struct rom_triple {
>     char *file1,*file2,*file3;
>     int length;
> };
> 
> struct rom_map {
>     rom_double *program_roms;
>     rom_triple *tile_roms;
>     rom_double *sprite_roms;
> };
> 
> As an example of a simple predefined structure:
> 
> struct rom_map game1_map = {
>     {    /* program roms */
>         {"progrom1a","progrom1b",65536},
>         {"progrom2a","progrom2b",65536},
>         {NULL, NULL, 0}
>     },
> 
>     {    /* tile roms */
>         {"tilerom1a","tilerom1b","tilerom1c",65536},
>         {NULL, NULL, NULL, 0}
>     },
> 
>     {    /* sprite roms */
>         {"spriterom1a","spriterom1b",65536},
>         {"spriterom2a","spriterom2b",65536},
>         {"spriterom3a","spriterom3b",65536},
>         {"spriterom4a","spriterom4b",65536},
>         {NULL, NULL, 0}
>     }
> };
> 
> However, when I compile it tons of warnings are generated, so I'm obviously
> doing something hideously wrong, but I can't see what.

Well, I'm not sure what your emulation and rom stuff is (something like
zsnes or nesticle?) but you do have a major problem in your code.

When you define a pointer, you must allocate memory in order to assign
values to it.

ex.

#include <stdio.h>
#include <string.h>

#define STRING_LENGTH 25

char *mystring;

void main() {
    //Allocate some memory, have mystring point to it.  You should test
    //for non-zero return val...
    mystring = (char *)malloc(STRING_LENGTH); 

    //Copy "Hello" to the memory location pointed to by mystring 
    //ie. the memory previously allocated with malloc.
    strcpy(mystring,"Hello");

    //Print this message
    printf("%s/n",mystring);

    exit(0);
    }

Any questions?  Post a follow up...

-Mike

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019