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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:53:47+00:00 2026-05-15T11:53:47+00:00

I have this typedef: typedef union { unsigned Value; unsigned Timestamp:16; } BITFIELD; and

  • 0

I have this typedef:

typedef union
{
    unsigned Value;
    unsigned Timestamp:16;
} BITFIELD;

and get this compiler warning:

BITFIELD bitfield;

// read from uninitialised memory - may result in unexpected behaviour
bitfield.Timestamp = 12;

Now, the warning disappears when I use a short instead of the bitfield:

typedef union
{
    unsigned Value;
    unsigned short Timestamp;
} DATATYPE;

I am not sure what to think about this warning – I don’t understand it. There is no uninitialised memory involved and no read operation, too. IMHO the compiler (VisualDSP++ 5.0 C/C++ Compiler) is wrong here. The warning disappears also, when I use a :32 bitfield for Timestamp.

Is there anything I didn’t realize? Can I safely ignore this warning?

  • 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-15T11:53:48+00:00Added an answer on May 15, 2026 at 11:53 am

    How big is an unsigned int on your system?

    The only thing I can think of that may cause this is if the 16 bit bitfield forms only part of the Timestamp variable (if, for example, an unsigned int is 32 bits wide).

    In other words, maybe the compiler is turning that into:

    Timestamp = (Timestamp & 0xffff0000) | 12;
    

    which would cause that problem if Timestamp were uninitialised.

    That fits in with:

    • using a 16-bit short since the code would probably just then become Timestamp = 12;.
    • using :32 since, it expands the bitfield to the point where a direct assignment is also possible.

    Pure supposition on my part but, discounting a brain-dead compiler, that’s the best I can come up with (if it’s true, it’s probably still brain-dead but in a different way).

    FWIW, gcc doesn’t complain even with -Wall.

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

Sidebar

Related Questions

If I have a class like this: typedef union { __m128 quad; float numbers[4];
If I have a struct like this: typedef struct { unsigned char c1; unsigned
I have this structure typedef struct fpinfo { unsigned long chunk_offset; unsigned long chunk_length;
I have a union as follows: typedef unsigned long GT_U32; typedef unsigned short GT_U16;
For example, say we have a union typedef union { unsigned long U32; float
I have following struct defination: typedef union U08_16_t { unsigned long s32;//message32 unsigned char
I have this struct: typedef struct { void (*func)(instruction); union { double db; char
I have a union that is defined like this: typedef union { enum {
I have a C struct like this: typedef struct { my_domain_type_t type; my_domain_union_t u;
In sample code, I have seen this: typedef enum Ename { Bob, Mary, John}

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.