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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:08:02+00:00 2026-06-18T11:08:02+00:00

typedef union { unsigned x; } T; T a; a.x = 3; int main()

  • 0
typedef union { unsigned x; } T;

T a;
a.x = 3;

int main() { return 0; }

Trying to compile this code, with gcc t.c, I get

error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token

using

gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

When I move a.x = 3; inside main, it behaves as expected.

I wish to find the passage from

ISO/IEC 9899:TC3

where it is explained that it is forbidden to assign values to a union in global namespace.


EDIT: with structures it happens the same.

  • 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-06-18T11:08:04+00:00Added an answer on June 18, 2026 at 11:08 am

    I wish to find the passage from ISO/IEC 9899:TC3 where it is explained that it is forbidden to assign values to a union in global namespace.

    It is described in the 6.9p1 of C99 (syntax of a translation-unit). You cannot have a statement outside of a function.

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

Sidebar

Related Questions

I have this typedef: typedef union { unsigned Value; unsigned Timestamp:16; } BITFIELD; and
I have the following type definition: typedef union{ unsigned int Entry; struct { unsigned
The following code: #include <stdio.h> typedef union { int n; char *s; } val_t;
If I have a class like this: typedef union { __m128 quad; float numbers[4];
I am trying to use a malloc of short, something like typedef union _SOME_STRUCT_
I have the following struct: typedef union { struct { unsigned char ID; unsigned
typedef union epoll_data { void *ptr; int fd; __uint32_t u32; __uint64_t u64; } epoll_data_t;
I have a union as follows: typedef unsigned long GT_U32; typedef unsigned short GT_U16;
I am using the following union declaration in SSE2. typedef unsigned long uli; typedef
I am trying to combine two 8-bit number to an unsigned int but no

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.