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.
How do you deal with FourCC
Re: How do you deal with FourCC
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.
"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.
Every good solution is obvious once you've found it.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How do you deal with FourCC
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
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
Last edited by Combuster on Wed Mar 07, 2012 9:04 am, edited 1 time in total.
Re: How do you deal with FourCC
I never got those printf() qualifiers commited to memory.
Every good solution is obvious once you've found it.