Hi, I have a bunch of hex constants I'd like to define with new names for characters for an LCD driver I'm writing.

Can I just define them in hex in the header like this:

#define NINE 0x39

Do I have to force #define statements into char like this?

#define NINE (char)0x39

will the hex work in the #define declaration or do I have to use decimal numbers like this:

#define NINE (char)63

I'd like to keep it hex if possible.


Thanks for any help in advance, Glen.

Recommended Answers

All 6 Replies

You can use your first example

#define NINE 0x39

Ok great. Does it store as a char? Or is that program specific?

Thought so, I was hoping I could force it to be a char...

Thought so, I was hoping I could force it to be a char...

You could cast it to character.

#include <stdio.h>

#define NINE (char)0x39

int main()
{
  fprintf(stdout, "%c %lu\n", NINE, sizeof(NINE));
  return 0;
}

Just use it. The compiler will compensate for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.