How do you deal with FourCC

Programming, for all ages and all languages.
Post Reply
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

How do you deal with FourCC

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How do you deal with FourCC

Post 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.
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
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

Post 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
Last edited by Combuster on Wed Mar 07, 2012 9:04 am, edited 1 time in total.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How do you deal with FourCC

Post by Solar »

I never got those printf() qualifiers commited to memory. :D
Every good solution is obvious once you've found it.
Post Reply