Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C string pointers

Name: Anonymous 2010-07-02 9:46

Hi, I've done following ugly thing in C:

void cmd_print_error_start(cmd_err_t error)
{
    char* errstr;
    switch(error)
    {
        case cmd_err_buffer   : { errstr = "BUFFER OVERFLOW"    ; break; }

...

        case cmd_err_rpc_id   : { errstr = "UNKNOWN RPC ID"     ; break; }
    }
    cmd_print("ERROR: %02hX %s", error, errstr);
}


When I compile it with GNU it works, with Keil compiler it spews out random memory until a null byte is reached.
I'm just curious: what does standart say about this? Does anyone know?

Name: Anonymous 2010-07-02 9:49

STANDARIZE MY ANUS

Name: Anonymous 2010-07-02 9:53

>>2
helpful post already; didn't expect that

Name: Anonymous 2010-07-02 9:59

it says USE LESS LITERALS IN YOUR CODE

Name: Anonymous 2010-07-02 10:03

put a default in your switch.

Name: Anonymous 2010-07-02 10:42

>>5
Or initialize errstr to something in its declaration.

Name: Anonymous 2010-07-02 10:56

>>5
noted, I was going to do that

>>5
>>6
but you both miss the point

Name: Anonymous 2010-07-02 11:05

Perhaps it's nothing to do with cmd_print_error_start, and instead the problem lies in cmd_print.

Name: Anonymous 2010-07-02 11:35

>>8

Nah, it's clearly incorrect pointer. cmd_print is basically printf to serial port and works fine.

Name: Anonymous 2010-07-02 11:50

>>9
Then fix the damn pointer.  Why are you ignoring people (>>5,6) who tell you the solution?

Name: Anonymous 2011-02-04 19:37


Don't change these.
Name: Email:
Entire Thread Thread List