Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:11:21+00:00 2026-06-17T07:11:21+00:00

A lot of the constants associated with Audio Session programming are really four-character strings

  • 0

A lot of the constants associated with Audio Session programming are really four-character strings (Audio Session Services Reference). The same applies to the OSStatus code returned from functions like AudioSessionGetProperty.

The problem is that when I try to print these things out of the box, they look like 1919902568. I can plug that into Calculator and turn on ASCII output and it’ll tell me “roch”, but there must be a programmatic way to do this.

I’ve had limited success in one of my C functions with the following block:

char str[20];
// see if it appears to be a four-character code
*(UInt32 *) (str + 1) = CFSwapInt32HostToBig(error);
if (isprint(str[1]) && isprint(str[2]) && isprint(str[3]) && isprint(str[4])) {
    str[0] = str[5] = '\'';
    str[6] = '\0';
} else {
    // no, format as integer
    sprintf(str, "%d", (int)error);
}

What I want to do is to abstract this feature out of its current function, in order to use it elsewhere. I tried doing

char * fourCharCode(UInt32 code) {
    // block
}
void someOtherFunction(UInt32 foo){
    printf("%s\n",fourCharCode(foo));
}

but that gives me “à*€/3íT:ê*€/+€/”, not “roch”. My C fu isn’t very strong, but my hunch is that the above code tries to interpret the memory address as a string. Or perhaps there’s an encoding issue? Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:11:23+00:00Added an answer on June 17, 2026 at 7:11 am

    The type you’re talking about is a FourCharCode, defined in CFBase.h. It’s equivalent to an OSType. The easiest way to convert between OSType and NSString is using NSFileTypeForHFSTypeCode() and NSHFSTypeCodeFromFileType(). These functions, unfortunately, aren’t available on iOS.

    For iOS and Cocoa-portable code, I like Joachim Bengtsson’s FourCC2Str() from his NCCommon.h (plus a little casting cleanup for easier use):

    #include <TargetConditionals.h>
    #if TARGET_RT_BIG_ENDIAN
    #   define FourCC2Str(fourcc) (const char[]){*((char*)&fourcc), *(((char*)&fourcc)+1), *(((char*)&fourcc)+2), *(((char*)&fourcc)+3),0}
    #else
    #   define FourCC2Str(fourcc) (const char[]){*(((char*)&fourcc)+3), *(((char*)&fourcc)+2), *(((char*)&fourcc)+1), *(((char*)&fourcc)+0),0}
    #endif
    
    FourCharCode code = 'APPL';
    NSLog(@"%s", FourCC2Str(code));
    NSLog(@"%@", @(FourCC2Str(code));
    

    You could of course throw the @() into the macro for even easier use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see a lot of objective-c code that just #defines local constants it needs,
Possible Duplicate: When to use std::size_t? I have a lot of constants in my
We do a lot of lexical processing with arbitrary strings which include arbitrary punctuation.
I'm programming using C#, after programming on C. So I'm using a lot of
I have a website which uses a lot of constants, that are defined like
I'm making a program that has a lot of constants. I decided to put
I use a lot of NSString constants like: static NSString * const REAColorPlaybackBackgroundKey =
Here is the problem: Constants: 'a', 'b', 'c', 'd'; I have a lot of
In C, shall I prefer constants over defines? I've reading a lot of code
I've C code that use a lot of commands identified by static string constants.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.