in ANSI-C a structure or union may not contain instances of itself, but
it may contain pointers to instances of itself. For example:
struct s {
int a,b;
float c;
struct s *pointer_to_s; /* This is legal */
};
An Objective-C program, which compiles correct under Stepstone
Objective-C, is compiled incorrect under gcc. A stripped down
source (Bug.m) reveals a core dump:
// start source file Bug.m
#include <objc/Object.h>
typedef union anUnion {
char my_char;
int my_int;
#ifdef NOBUG
double my_double;
#endif
union anUnion *anUnionPtr;
} tUnion;
@implementation Bug : Object
{
}
- (tUnion)message {
}
@end
// end source file Bug.m
Example of compilation error:
$ gcc -c Bug.m
Bug.m:14: warning: Cannot find interface declaration for `Bug'
gcc: Internal compiler error: program cc1obj got fatal signal 11
When it is compiled without leaving out the line (see source file above)
"double my_double;"
it compiles without a core-dump, which is very strange I think:
$ gcc -c -DNOBUG Bug.m
Bug.m:14: warning: Cannot find interface declaration for `Bug'
$
An self-referencing union in C gives also no problems:
// start source file Bug.c
typedef union anUnion {
char my_char;
int my_int;
union anUnion *anUnionPtr;
} tUnion;
tUnion message(void) {
}
// end source file Bug.c
$ gcc -c Bug.c
$
The gcc-option -v gives the following output:
$ gcc -v -c Bug.m
Reading specs from
/site/gnu/solaris/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2.1/specs
gcc version 2.7.2.1
/site/gnu/solaris/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2.1/cpp
-lang-objc -v -I. -undef -D__OBJC__ -D__GNUC__=2 -D__GNUC_MINOR__=7
-Dsun -Dsparc -Dunix -D__svr4__ -D__SVR4 -D__GCC_NEW_VARARGS__ -D__sun__
-D__sparc__ -D__unix__ -D__svr4__ -D__SVR4 -D__GCC_NEW_VARARGS__ -D__sun
-D__sparc -D__unix -Asystem(unix) -Asystem(svr4) -Acpu(sparc)
-Amachine(sparc) Bug.m /tmp/cca000wg.i
GNU CPP version 2.7.2.1 (sparc)
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/site/gnu/solaris/sparc-sun-solaris2.5/include
/site/gnu/solaris/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2.1/include
/usr/include
End of search list.
/site/gnu/solaris/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2.1/cc1obj
/tmp/cca000wg.i -quiet -dumpbase Bug.m -version -lang-objc -o
/tmp/cca000wg.s
GNU Obj-C version 2.7.2.1 (sparc) compiled by GNU C version 2.7.2.1.
Bug.m:14: warning: Cannot find interface declaration for `Bug'
gcc: Internal compiler error: program cc1obj got fatal signal 11
We are using Solaris 2.5.1 and gcc 2.7.2.1.
I am not interested in a workaround, but want to know if this, imho
ANSI-C program, should compile correct under gcc Objective-C.
The more it compiles correct adding the double in the union.
Maybe it is an alignment problem?
Am I right it is a gcc Objective-C bug?
Rick Everaerts,
Software Developer, Philips Medical Systems
Email:rick.ev...@best.ms.philips.com
Phone:+31 40 27 62047 Fax:+31 40 27 63393
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
Yes, this looks like a gcc bug. It also occurrs on Intel and PowerPC
architectures with gcc 2.7.2.1, so I don't think it's alignment-related.
Looks like it's getting caught in an infinite recursion somewhere (the
process size rises without bound).
--
Mark Bessey
Apple Computer, Inc.
-->I DON'T SPEAK FOR APPLE<--
It compiles all-right for me:
> Microsoft(R) Windows NT(TM)
> (C) Copyright 1985-1996 Microsoft Corp.
>
> C:\>cd stes
>
> C:\STES>objc -q -c bug.m
> bug.m:17: warning (objc1): Cannot find interface declaration for "Bug"
> bug.m(19): Warning! W107: Missing return value for function 'i_Bug_message'
As far as returning structs and unions concerns, I'm curious as to
whether you use a Stepstone compiler with the "all C" messenger (-CMsg)
or an older version (with a 3-arg messenger).
The more recent C messenger was intended to make the issues of return
values that are not "id", more portable ...
Although I'm not sure it's a good idea anyhow to have
methods return a struct or union etc.; seems you can as well return
an Object ... (with the extra advantage that these instances are then
compatible with all sorts of classes like Set, Tree, Collection etc.)
David.
David,
we are using the more recent Stepstone compiler (C messenger with -CMsg).