Page 1 of 1

How do you deal with FourCC

Posted: Wed Mar 07, 2012 7:12 am
by bluemoon
I have intensive usage of fourCC, and I found it lame to convert it into string before passing to snprintf, now I injected 4cc support into snprintf (with %$ token, hopefully don't conflict with anything)...

So, how would you deal with 4cc?

a) don't care, just print as hex
b) convert to 5 bytes string first
c) make 4cc aware snprintf-alike, or warp it
d) macro
e) I don't use 4cc
f) I have smarter way.

Re: How do you deal with FourCC

Posted: Wed Mar 07, 2012 7:50 am
by Solar
That's about as close to an original business service request as it gets.

"What the heck is a 'fourCC'? What are you talking about? What do you need this for?"

Nevermind, I WP'ed it.

So. Since I do not know any C/C++ datatype called "FourCC", I have to assume that you have a 32-bit integer that "in reality" is a four-byte unterminated character string, right?

I'd start with %4c and see where that takes me. Of course, this is ugly, and probably not textbook legal, and I certainly wouldn't do this in production code (where I probably would use a macro or a function, depending on the frequency of usage). But it's an easy start.

Re: How do you deal with FourCC

Posted: Wed Mar 07, 2012 8:59 am
by Combuster
It's actually "%.4s" for at most four characters. You're trying to prepend spaces until a minimum of 4 characters have been obtained...

I've seen FourCCs defined as char[4] and various ints with or without portability issues. People seem to favor the macro to cast a string constant to an 32-bit int

Re: How do you deal with FourCC

Posted: Wed Mar 07, 2012 9:02 am
by Solar
I never got those printf() qualifiers commited to memory. :D