6

I have following define in my code

#define PRODUCTNAME     "SomeName"

and I want to send it with a function com_reply(unsigned char* msg, uint16_t lenght).

Now I get a warning that my argument differs in signedness. I know what the problem is and also why com_reply uses unsigned char* instead of char*, I just want to know:

How can I define my string as an unsigned char* so I can use it throughout my program without getting warnings all over the place.

EDIT:

Strictly speaking I have more than one defines here and the main reason is that there is a BANNER define which consists of several other defines, like this:

#define PRODUCTNAME     "SomeName"
#define PRODUCTDATE     "2013-03-30"
#define BANNER          PRODUCTNAME " (" PRODUCTDATE ")"

Should I create const variables and concatenate them at program start instead of using defines here?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Dehalion
  • 757
  • 1
  • 7
  • 16
  • 1
    Why not `const char* PRODUCTNAME = "SomeName"` or similar? (unrelated, but #define has plenty of disadvantages for this.) – Jacob Parker Mar 30 '13 at 15:23
  • 1
    I dunno how standard-compliant this is, but what about: `(const unsigned char*)"SomeName"` – Mysticial Mar 30 '13 at 15:23
  • 2
    Out of curiosity, what does the `com_reply` function do? It seems like it's something that shouldn't actually take a string, but rather a pointer to a number between 0 and 255. – austin Mar 30 '13 at 15:26
  • `com_reply` is used to send all kind of things, mostly binary data, sometimes human readable strings. that's why it takes `unsigned char*` – Dehalion Mar 30 '13 at 15:28
  • Does `com_reply` declare its parameters `const`? If not, you'll get a warning sending one. – teppic Mar 30 '13 at 15:39
  • No, the definition is just like i put it here – Dehalion Mar 30 '13 at 15:41

1 Answers1

12

This should work:

#define PRODUCTNAME     ((const unsigned char *)"SomeName")
thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110