1

Does anyone know how should ASF_OBJECT_GUID_TEST be defined to avoid compilation error in the line marked below, or where I can find more information about it?

#define ASF_OBJECT_GUID_TEST {(char)0x75, (char)0xB2, (char)0x00}

void testFunction(char * testChar)
{

}

int main(int argc, char * argv[])
{
   char test[] = ASF_OBJECT_GUID_TEST;

   testFunction(test);
   testFunction(ASF_OBJECT_GUID_TEST); // <- fails to compile this line of code

   return 0;
}
1
  • If your data is know at compile time, you can say #define ASF_OBJECT_GUID_TEST "\x75\xB2". Commented Feb 4, 2010 at 5:53

3 Answers 3

2
{(char)0x75, (char)0xB2, (char)0x00}

is an initializer list and is not itself an array (or a pointer) in C89.

You instead could use:

#define ASF_OBJECT_GUID_TEST "\x75\xB2"
Sign up to request clarification or add additional context in comments.

Comments

1

you want to cast the ASF_OBJECT_GUID_TEST, i.e

testFunction((char[])ASF_OBJECT_GUID_TEST)

or

#define ASF_OBJECT_GUID_TEST (char[]){(char)...}

1 Comment

The (char) casts inside the curly braces are not needed of course (you probably know this, so the comment is mostly for the OP). Also, this is C99 only.
0

Thanks. That was exactly what I was looking for.

Supposed I have defined many string literals which have 8 characters, and each 2 of them make actually the value of a byte. Is there a way to create a macro that would modify those string literals by adding a "\x" between every couple of characters like the following?

#define TEST SOME_MACRO("33698149")

Where TEST would be "\x33\x69\x81\x49"

2 Comments

This should be asked as a new question, or you should edit your original post to include this question.
Definitely a new question, although the short answer is "no, you can't do that".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.