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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:19:53+00:00 2026-05-28T01:19:53+00:00

Given I have a type specifier as returned by method_copyReturnType(). In the GNU runtime

  • 0

Given I have a type specifier as returned by method_copyReturnType(). In the GNU runtime delivered with the GCC there are various methods to work with such a type specifier like objc_sizeof_type(), objc_alignof_type() and others.

When using the Apple runtime there are no such methods.

How can I interpret a type specifier string (e.g. get the size of a type) using the Apple runtime without implementing an if/else or case switch for myself?

[update]

I am not able to use the Apple Foundation.

  • 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-28T01:19:54+00:00Added an answer on May 28, 2026 at 1:19 am

    afaik, you’ll need to bake that info into your binary. just create a function which returns the sizeof and alignof in a struct, supports the types you must support, then call that function (or class method) for the info.

    The program below shows you that many of the primitives are just one character. So the bulk of the function’s implementation could be a switch.

    static void test(SEL sel) {
        Method method = class_getInstanceMethod([NSString class], sel);
    
        const char* const type = method_copyReturnType(method);
    
        printf("%s : %s\n", NSStringFromSelector(sel).UTF8String, type);
    
        free((void*)type);
    }
    
    int main(int argc, char *argv[]) {
        @autoreleasepool {
    
            test(@selector(init));
            test(@selector(superclass));
            test(@selector(isEqual:));
            test(@selector(length));
    
            return 0;
      }
    }
    

    and you could then use this as a starting point:

    typedef struct t_pair_alignof_sizeof {
        size_t align;
        size_t size;
    } t_pair_alignof_sizeof;
    
    static t_pair_alignof_sizeof MakeAlignOfSizeOf(size_t align, size_t size) {
        t_pair_alignof_sizeof ret = {align, size};
        return ret;
    }
    
    static t_pair_alignof_sizeof test2(SEL sel) {
        Method method = class_getInstanceMethod([NSString class], sel);
        const char* const type = method_copyReturnType(method);
        const size_t length = strlen(type);
    
        if (1U == length) {
            switch (type[0]) {
                case '@' :
                    return MakeAlignOfSizeOf(__alignof__(id), sizeof(id));
                case '#' :
                    return MakeAlignOfSizeOf(__alignof__(Class), sizeof(Class));
                case 'c' :
                    return MakeAlignOfSizeOf(__alignof__(signed char), sizeof(signed char));
                ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read the documentation that states that "given the type of the enum,
Given you have the following class (bad C#, but you get the drift): public
Given I have a master branch and a other branch. In the other branch
Given I have two File objects I can think of the following implementation: public
given i have the following block of code (function(){ var mb = { abc:function(){
Given: I have an interface. I have only class that implements that interface. Question:
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
I have given a location defined by latitude and longitude. Now i want to
I have given a table background image using css background-image property. The cells are
Note: I have given up on compiling iPhone Apps without a developer certificate for

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.