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 6876019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:25:33+00:00 2026-05-27T04:25:33+00:00

Given an Objective-C type type , one can obtain the encoding encoding and size

  • 0

Given an Objective-C type type, one can obtain the encoding encoding and size size of the type easily:

const char *encoding = @encode(type);
size_t size = sizeof(type);

Put a little differently, we have mappings

@encode: type_t -> const char *
sizeof:  type_t -> size_t

This raises two questions:

(1) Suppose that rather than having a type, we have only an encoding. It would be nice to obtain a mapping

sizeofencodedtype: const char * -> size_t

such that for every type_t type we have that

sizeofencodedtype(@encode(type)) = sizeof(type)

Does such a function already exist? If not, how might one go about building one?

(2) Ideally we could invert the @encode mapping to make a mapping

decode: const char * -> type_t

but this doesn’t seem to be possible since type_t isn’t a real C type. I guess I could wait for @decode to be added to the language, but that’s not very realistic or time-sensitive. But should it not be possible to instantiate a type at runtime using its encoding?

References:
Objective-C Runtime Programming Guide – Type Encodings

  • 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-05-27T04:25:34+00:00Added an answer on May 27, 2026 at 4:25 am

    NSGetSizeAndAlignment() can do this for you. It’s also a useful function if you’re trying to grope through multiple types in the same string.

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

Sidebar

Related Questions

In Objective-C, how can one find out whether a given class serves as a
Given an IBOutlet pointer in Objective-C/iPad, how do you hide that element? Want to
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
I know that you can do one of the following things when declaring the
I'm trying to figure out if I can use dot syntax in objective c
I'm trying to learn Objective C & Cocoa, but I just can't manage to
Is it possible to set the return type of a selector in objective-c to
Very simple problem: given two CLLocationCoordinate2Ds, how can I get the bearing (as radians)
I'd like to give Objective-C a try in game programming. The problem is I'd
Given I have a class with two constructors: public class TestClass { ObjectOne o1;

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.