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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:06:17+00:00 2026-05-30T15:06:17+00:00

I want to specify an enumeration size of 64 bits for an enumeration. How

  • 0

I want to specify an enumeration size of 64 bits for an enumeration. How is this possible through GCC? The code does not need to be ‘portable’ in that I am only interested in making the code work on GCC compiling for x86-32 and x86-64 Linux. That means any hack which can provide the functionality I want is fine as long as it works for those targets.

Given this code:

#include <stdlib.h>
#include <stdio.h>

enum some_enum
{
    garbage1,
    garbage2
};

int main(void)
{
    enum some_enum some_val;
    printf("size: %lu\n", sizeof(some_val));

    return EXIT_SUCCESS;
}

This currently prints out 4, whereas I want to be able to force the size to be 8. Attempting to specify values in the enum assignment larger than 4 bytes cause a warning. For example,

enum some_enum
{
    garbage1 = '12345',
    garbage2
};

Would produce:

warning: character constant too long for its type [enabled by default]

An answer to a similar question here doesn’t seem to yield any good results. That is, the same warning is produced as a result of:

enum some_enum
{
    garbage1 = 'adfs',
    garbage2 = 'asdfasdf'
};

Note: the multi-character warning can be turned off by compiling with -Wno-multichar.


Rationale

Since people are interested in why I am doing this, I have written a disassembler engine. I get each part of an instruction as a string. So I want the enumeration to look like this:

enum mnemonic
{
    mov = 'mov',
    cmp = 'cmp',
    sysenter = 'sysenter'
};

I can then store semantic information easily with some code like this:

enum mnemonic insn;

char *   example_insn = "mov";
uint64_t buf          = 0;

strncpy((char *)&buf, example_insn, sizeof(uint64_t));

If buf were an enum mnemonic then we need to do nothing else. The strncpy is used to pad the bytes after the end of the string to null characters. If I am not able to do this, I would have to do something like this instead:

if(strcmp(example_insn, "mov") == 0) {
    insn = mov;
} else if(strcmp(example_insn, "cmp") == 0) {
    insn = cmp;
} ...

Since this routine is going to be hit millions of times, this sort of optimisation would make a huge difference. I intend to do the same for operands such as registers too.

  • 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-30T15:06:18+00:00Added an answer on May 30, 2026 at 3:06 pm

    You’ve misinterpreted the warning, what it’s saying is that character literals are always of type int, never of type long or long long.

    You can get away with something like this:

    enum foo {
        garbage1 = (long long)'1' << 32 | (long long)'2' << 24 | (long long)'3' << 16 | (long long)'4' << 8 | (long long)'5',
        garbage2
    };
    

    But you still have to be careful about using little endian if you want to use the strncpy solution, make sure to use the correct shift numbers.

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

Sidebar

Related Questions

I want to specify that the size is 200dlu < preferred component size <
I want to specify that either fieldname or freetext must always be present in
I have a Java WebStart application for which I want to specify that the
Can I specify I want the preceding character to be either (NOT A DIGIT)
I would like to specify that I want FEATURE_INDETERMINATE_PROGRESS for my Activity . It
How to Specify NOT with Regular Expressions for Words I want to filter a
I want to specify a custom icon for a marker. Sadly, the icon that
I want to specify in my code to move to a specific activity after
Basically I want to specify all files that end with Test.dll, also known as
I don't want to specify hard coded test size values in my layout.xml, hence

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.