bugTiny C Compiler - Bugs: bug #56676, Strange initialization behavior

 
 

bug #56676: Strange initialization behavior

Submitter:  David KOCH <kochise>
Submitted:  Fri 26 Jul 2019 07:01:08 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Mar 2020 10:59:19 PM UTC, comment #1: 

```c
#include <stdio.h>
typedef struct test
{ uint32_t one:1;
uint32_t two:1;
uint32_t three:1;
uint32_t four:2;
uint32_t five:1;
};

int main(void)
{
// Initialization result depends on the order of them
struct test s_a; // -> 0x0000037F
struct test s_b = { }; // -> 0x00000000
struct test s_c = { 0 }; // -> 0x00001F80
struct test s_d = { 0, }; // -> 0x00E86CE8
struct test s_e = { { 0 } }; // -> 0x00000000

printf("s_a = 0x%08X\n", ((uint32_t*)&s_a)[0]);
printf("s_b = 0x%08X\n", ((uint32_t*)&s_b)[0]);
printf("s_c = 0x%08X\n", ((uint32_t*)&s_c)[0]);
printf("s_d = 0x%08X\n", ((uint32_t*)&s_d)[0]);
printf("s_e = 0x%08X\n", ((uint32_t*)&s_e)[0]);

// uncomment block comment and comment 2 code blocks above for testing
/* struct test s_d = { 0, };
struct test s_b = { };
struct test s_a; // -> 0x0000037F
struct test s_e = { { 0 } };
struct test s_c = { 0 };


printf("s_c = 0x%08X\n", ((uint32_t*)&s_c)[0]);
printf("s_a = 0x%08X\n", ((uint32_t*)&s_a)[0]);
printf("s_d = 0x%08X\n", ((uint32_t*)&s_d)[0]);
printf("s_b = 0x%08X\n", ((uint32_t*)&s_b)[0]);
printf("s_e = 0x%08X\n", ((uint32_t*)&s_e)[0]); */

return 0;
}
```


seems fine after testing. same results on Windows 10 with tcc 0.9.27. some sample output
```c
s_c = 0x00000000
s_a = 0x00000000
s_d = 0x0014FF08
s_b = 0x00000000
s_e = 0x00000000

s_a = 0x00000000
s_b = 0x00000000
s_c = 0x00000000
s_d = 0x0014FF08
s_e = 0x00000000
```

Anonymous
Fri 26 Jul 2019 07:01:08 AM UTC, original submission:  

// tab = 4
typedef struct test
{ uint32_t one:1;
uint32_t two:1;
uint32_t three:1;
uint32_t four:2;
uint32_t five:1;
};

int main(void)
{
// Initialization result depends on the order of them
struct test s_a; // -> 0x0000037F
struct test s_b = { }; // -> 0x00000000
struct test s_c = { 0 }; // -> 0x00001F80
struct test s_d = { 0, }; // -> 0x00E86CE8
struct test s_e = { { 0 } }; // -> 0x00000000

printf("s_a = 0x%08X\n", ((uint32_t*)&s_a)[0]);
printf("s_b = 0x%08X\n", ((uint32_t*)&s_b)[0]);
printf("s_c = 0x%08X\n", ((uint32_t*)&s_c)[0]);
printf("s_d = 0x%08X\n", ((uint32_t*)&s_d)[0]);
printf("s_e = 0x%08X\n", ((uint32_t*)&s_e)[0]);

return 0;
}

David KOCH <kochise>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by kochise (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.14-8eb0.
    Corresponding source code