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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:05:02+00:00 2026-05-28T17:05:02+00:00

Is it possible to pass an enum as a parameter to a variadic function?

  • 0

Is it possible to pass an enum as a parameter to a variadic function? I’m trying to do the following:

GLenum ShaderManager::initialize()
{
    GLuint program = loadShader("Flat", 2, ATTRIBUTE_VERTEX, "coord3d", ATTRIBUTE_TEXTURE0, "texcoord");

    //...
}


GLuint ShaderManager::loadShader(std::string shaderName, ... )
{
    GLuint program;

    //...

    va_list arglist;
    va_start(arglist, shaderName);

    int count = va_arg(arglist, int);
    for(int i = 0; i < count; i++) {
        AttributeLocation location = va_arg(arglist, AttributeLocation);
        char * name = va_arg(arglist, char *);
        glBindAttribLocation(program, location, name);
    }
    va_end(arglist);

    //...
}

Where both ATTRIBUTE_VERTEX and ATTRIBUTE_TExTURE are declared as

enum AttributeLocation {
        ATTRIBUTE_VERTEX = 0,
        ATTRIBUTE_COLOR,
        ATTRIBUTE_NORMAL,
        ATTRIBUTE_TEXTURE0
    };

But the program just terminates. I’ve found out, debugging the program, that the error occurs on the first line after the for loop. So I’m wondering if it is possible to do it or it’s something illegal.

  • 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-28T17:05:03+00:00Added an answer on May 28, 2026 at 5:05 pm

    This is because passing integral types that are less than sizeof(int) bytes big to a varargs function will convert them up to sizeof(int) bytes when passed on the stack. If AttributeLocation smaller than sizeof(int) bytes, then sizeof(int) bytes are pushed on the stack, but you retrieve only sizeof(AttributeLocation) bytes from the stack with the va_arg call. Then when you try to read the char*, you get the rest of the bytes of the AttributeLocation and some of the bytes of the const char* that you passed.

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

Sidebar

Related Questions

Is it possible to do the following with an enum in C#?: Pass in
Is it possible to pass a function as parameter to a method and evaluate
Possible Duplicate: Pass a data.frame column name to a function I am trying to
Is it possible to pass a jQuery method as a parameter into a function
Is it possible to pass a reference to a function to another function in
Is it possible to pass a function/callback from javascript to a java applet? For
Is it possible to pass a list constructor parameter when resolving a type? I
Is it possible to pass command line arguments into a function from within a
Is it possible to pass parts of a linq Query into a function? I
Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value

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.