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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:06:15+00:00 2026-05-14T03:06:15+00:00

Suppose I have the following: typedef enum functionType {ln, sin, sqrt} functionType; NSArray *functions

  • 0

Suppose I have the following:

typedef enum functionType {ln, sin, sqrt} functionType;
NSArray *functions = [NSArray arrayWithObjects: @"ln", @"sin", @"sqrt", nil];

Suppose further that *functions will not change at runtime.

Question — is there any way to set up a single structure which updates both of these? So that I only have to keep track of one list, instead of two.

To explain what is going on — the idea is that string input from the user will be stored in a variable of type functionType. Later on, I will have code like this:

double valueOfFunction: (functionType) function withInput: (double) input
  switch (function) {
    case ln:
      return ln(input);
    case sin:
      return sin(input);
    case sqrt:
      return sqrt(input);
    //etc . . . could grow to include a lot of functions.
  }

And valueOfFunction needs to be fast. So I don’t want to be doing string comparisons there.

  • 1 1 Answer
  • 1 View
  • 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-14T03:06:15+00:00Added an answer on May 14, 2026 at 3:06 am

    It sounds like you want a map from strings to enum objects. There are a number of ways to do this.

    You could use an NSDictionary with NSString keys and NSNumber-encoded ints representing the objects.

    You could use an NSArray of the function names (@”ln”, @”sin”, etc), and only store the index into the array; this basically gets rid of the enum.

    If you really want a joined list of enum types and string objects, you could also do something like this:

    typedef enum FunctionType {
      ln, sin, cos, tan, exp
    } FunctionType;
    
    typedef struct FunctionItem {
      FunctionType type;
      NSString *name;
    } FunctionItem;
    
    FunctionItem functions[] = {
      {ln, @"ln"},
      {sin, @"sin"},
      {cos, @"cos"},
      {tan, @"tan"},
      {exp, @"exp"},
    };
    

    Watch out for symbol clashes, though! You can’t have an enum identifier called sin and also use the standard sin() function.

    Good luck with your calculator-type app!

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

Sidebar

Related Questions

Suppose I have the following: typedef struct { int itemSize; int count; void *list;
Suppose I have the following struct and function returning a pointer: typedef struct {
Suppose i have following WCF Services. UtilityService (Service to provide utility functions) SomeOtherService 1
Suppose I have the following code: typedef struct { char **p; } STRUCT; int
Suppose a long time ago, I had created the following enumeration: typedef enum {
suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following simple struct: struct Vector3 { double x; double y;
Suppose I have the following js code: r='d|daa|dd'; reg = /\|.*/; result = reg.exec(r);

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.