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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:07:14+00:00 2026-05-16T08:07:14+00:00

I have a struct: struct s { UINT_PTR B_ID; }; s d; d.B_ID=0x1; That

  • 0

I have a struct:

struct s
{
    UINT_PTR B_ID;
};
s d;
d.B_ID=0x1;

That works fine, but I want d.B_ID to be constant. I tried to use (const) but it didn’t work. So after I put a value to d.B_ID, then I want make it a constant.

Any ideas?


EDIT

ok i don’t want the whole struct a constant.

when i set timer and use the b.B_ID as an idea for the timer.
in the

switch(wparam)
{
case b.B_ID // error: B_ID must be constant
….
break;
}

so that is why i need it to be a constant

  • 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-16T08:07:15+00:00Added an answer on May 16, 2026 at 8:07 am

    Variable modifiers are fixed at compile time for each variable. You may have to explain the context of what you are trying to do, but perhaps this will suit your needs?

    struct s
    {
      int* const B_ID;
    };
    
    int main (void) {
      int n = 5;
      s d = {&n};
      int* value = d.B_ID; // ok
      //  d.B_ID = &n; // error
      return 0;
    }
    

    Since you are using C++ I would recommend:

    class s {
    public:
        int* const B_ID;
    
        s (int* id) :
        B_ID (id) {
        }
    };
    
    void main (void) {
       int n = 5;
       s my_s_variable = s(&n);
    
       int* value = my_s_variable.B_ID; // ok
       //my_s_variable.B_ID = &n; // error
       return 0;
    }
    

    Ramiz Toma: well i need way to do it using the s.B_ID=something

    In C/C++ type modifiers (like const) are declared at run time for a given type and cannot be changed at run time. This means that if a variable is declared const it can never be assigned to using the assignment operator. It will only be assigned a value when it is constructed.

    This is not a problem however because you can always get around this by proper design.

    If you say you need to use assignment, I assume that this is because you create the struct before you know what the value of the variable will be. If this is the case then you simply need to move the struct declaration till after you know the value.

    For example

    s d; //variable declaration
    
    //calculate B_ID
    //...
    int* n = 5;
    //...
    
    
    d.B_ID = &n;
    

    This will not work, because if you want b.D_ID to be ‘un assignable’ it will always be so. You will need to refactor your code similarly to:

    //calculate B_ID
    //...
    int* n = 5;
    //...
    
    
    s d (&n);
    //good
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok well i have structure struct balls { balls(UINT_PTR const &val) : BALL_ID(val){} int
I have a struct, MyStruct , that has a private member private bool[] boolArray;
I have a struct that contains three lists and an integer as can be
I have a struct that looks something like: struct foo_t { template <std::size_t x,
I have a class here that is defined like this: struct USERFPOINT { POINTFLOAT
I have a dll which accepts a struct that contains a pointer to a
I have a C struct that is defined in a way similar to this:
I've just started to use boost multi_index and so far have a container that
Ok so I have struct like this typedef struct { float x; float y;
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a

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.