Bug 76986 - gcc fail to allocate storage for struct someways
gcc fail to allocate storage for struct someways
Status: CLOSED DUPLICATE of bug 76985
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-10-30 11:47 EST by Need Real Name
Modified: 2007-04-18 12:48 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-10-30 11:47:15 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2002-10-30 11:47:08 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

Description of problem:
1)When I define structed variables within a function/main as local variable 
using a structed type declared outside all the function/main at the beginning 
of the program, I always get "segmentation fault" 
from the running of compiler-passed program when I put a system-
declared struct definition "struct sigaction sa;" before my-declared 
struct definitions; sometimes gcc can find only one my-declared struct and 
sometimes none; 
2)When I define these variables outside the function/main as global variables 
after the structed type declarations, I only receive 
"segmentation fault" from the running of the compiler-passed program;
3)my declared struct is fixed-sized with 1 int and 2 unsigned char and
gcc should recognize, allocate storages for them, and initiate them by default 
when I define variables using these types, according Brian Richiete C book.  

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.copy the following program types.c into your pc redhat 7.3:
#include <stdio.h>
#include <signal.h>
//#include "types.h"
struct maketype {
int c0;
unsigned char c1;
unsigned char c2;
};	
//struct  maketype *m_c;
//struct  maketype *s_c;
typedef struct maketype Mt;
//Mt *m_c;
//Mt *s_c;

main () {
//struct sigaction sa;
struct  maketype *m_c;
struct  maketype *s_c;
//Mt *m_c;
//Mt *s_c;
	int i;
	printf("types Test!\n");
	m_c->c0 = 1;
	printf("types Test! m c0\n");
	m_c->c1 = 2;
	printf("types Test! m c1:%d\n",m_c->c1);
	m_c->c2 = 3;
	s_c->c0 = 10;
//	printf("types Test! s c0: %d\n",s_c->c0);
	for (i=0;i<4; i++) {
		printf("Mt c0:%d\n",m_c->c0);
//		sleep(3);
		m_c->c0++;
	}
}//end main


2.make or gcc types.c -o types directly

3.run types to see the stranges

4.comment out some lines of codes and/or add some lines of codes as
  one of the following options:
4.1 if line 16 "struct sigaction sa;" is kept there, using line 17,18
    "struct maketype *m_c; struct maketype *s_c;" or line 19,20 
    "Mt *m_c; Mt *s_c;", the returning is:
 
4.2 if line 16 is commented out, the returning is ok;
 
4.3 if line 19,20 "Mt *m_c; Mt *s_c;" are commented out and line 12, 
    13 "Mt *m_c; Mt *s_c;" or line 9,10 "struct maketype *m_c,*s_c;" 
    remains there, the returning is:


5.goto step 2. to see the results until all the options has been  
  selected or you don't think further options(adding your own option)
  are needed.



Actual Results:  * if line 16 "struct sigaction sa;" is kept there, using line 
17,18
* "struct maketype *m_c; struct maketype *s_c;" or line 19,20 
* "Mt *m_c; Mt *s_c;", the returning is:
[trouble:759]$ make clean
rm -f *.o  types
[trouble:760]$ make
gcc    -c -o types.o types.c
gcc   types.o   -o types
[trouble:761]$ types
types Test!
Segmentation fault
[trouble:762]$
 
* if line 16 is commented out, the returning is:
[trouble:768]$ make clean
rm -f *.o  types
[trouble:769]$ make
gcc    -c -o types.o types.c
gcc   types.o   -o types
[trouble:770]$ types
types Test!
types Test! m c0
types Test! m c1:2
Mt c0:1
Mt c0:2
Mt c0:3
Mt c0:4
Aborted
[trouble:771]$
 
* if line 19,20 "Mt *m_c; Mt *s_c;" are commented out and line 12,13 
* "Mt *m_c; Mt *s_c;" or line 9,10 "struct maketype *m_c,*s_c;" *
* remains there, the returning is:
[trouble:771]$ make clean
rm -f *.o  types
[trouble:772]$ make
gcc    -c -o types.o types.c
gcc   types.o   -o types
[trouble:773]$ types
types Test!
Segmentation fault
[trouble:774]$


Expected Results:  [trouble:770]$ types
types Test!
types Test! m c0
types Test! m c1:2
Mt c0:1
Mt c0:2
Mt c0:3
Mt c0:4
[trouble:771]$


Additional info:
Comment 1 Jakub Jelinek 2002-10-30 11:48:24 EST

*** This bug has been marked as a duplicate of 76985 ***

Note You need to log in before you can comment on or make changes to this bug.