Thread: define struct literally for returning a null version

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    80

    define struct literally for returning a null version

    Iíve got an array of structs defined like so:

    Code:
    struct character_data {
        char name[18];
        int width;
        int height;
        unsigned long data[66][1];
    };
    
    struct character_data chars_data[] = {
        { "0", 37, 66,
            { {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0xffe000}, {0x3fff800}, {0x7fffe00}, {0xfffff00}, {0x1fffff80}, {0x3fc03f80}, {0x3f801fc0}, {0x7f000fe0}, {0x7e0007e0}, {0xfc0007e0}, {0xfc0007f0}, {0x1fc0003f0}, {0x1f80003f0}, {0x1f80003f0}, {0x1f80003f8}, {0x1f80001f8}, {0x3f80001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f00001f8}, {0x3f80001f8}, {0x1f80001f8}, {0x1f80003f0}, {0x1f80003f0}, {0x1f80003f0}, {0x1fc0003f0}, {0xfc0007e0}, {0xfc0007e0}, {0x7e000fc0}, {0x7f001fc0}, {0x3f803f80}, {0x3fe0ff80}, {0x1fffff00}, {0xffffe00}, {0x7fffc00}, {0x3fff000}, {0x7fc000}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0}, {0x0} }
        },
    At the moment itís in a separate file as a global variable.

    In a function which finds and returns the right element from the chars_data array, Iím trying to define and return a null version of the character_data structure for when whatís being asked for isnít found.

    Eg
    Code:
        return (struct character_data){"null",0,0,{{0}} };
    }
    Tried a number of variations on that. Canít get it to work/compile. What should that be? Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,658
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 06-18-2015, 02:02 PM
  2. assign null value to a struct and check if it is null
    By ymc1g11 in forum C Programming
    Replies: 10
    Last Post: 11-01-2012, 03:58 PM
  3. how to define string without null at the end!?
    By hyaku_ in forum C Programming
    Replies: 6
    Last Post: 11-22-2006, 06:11 AM
  4. Replies: 1
    Last Post: 04-06-2003, 09:06 AM
  5. NULL Define - Why?
    By Davros in forum C++ Programming
    Replies: 22
    Last Post: 12-15-2002, 11:33 AM

Tags for this Thread