www.delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
From: | "Alan Cooley" <alan AT vacooley DOT com> |
To: | <cygwin AT sources DOT redhat DOT com> |
Subject: | gcc - static pointer initialization problem |
Date: | Thu, 7 Aug 2003 16:00:39 -0500 |
Message-ID: | <NDBBJGEAMLLLJFEHPBDMIEAOCIAA.alan@vacooley.com> |
MIME-Version: | 1.0 |
X-Priority: | 3 (Normal) |
X-MSMail-Priority: | Normal |
Importance: | Normal |
X-MimeOLE: | Produced By Microsoft MimeOLE V6.00.2800.1165 |
Note-from-DJ: | This may be spam |
------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello, I am having a problem with a C program. It appears that static variables are not being initialized when in an object file. The program compiles and links fine but funcPtrStruct.ptr is null so program crashes. This program works using gcc on Linux and (as I understand the C language) should work anywhere. Thanks in advance for any explanation/corrections you can provide. Alan. ---------------- Files attached: gccversion.txt - output of "gcc -v" Makefile - 'nuf said static_function_ptr_def.h - header for structure to hold function ptr static_function_ptr_def.c - implementation with static initializer static_function_ptr.c - main that invokes the function ------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: text/plain; name="gccversion.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gccversion.txt" Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs=0A= Configured with: /netrel/src/gcc-3.2-3/configure = --enable-languages=3Dc,c++,f77,java --enable-libgcj = --enable-threads=3Dposix --with-system-zlib --enable-nls = --without-included-gettext --enable-interpreter = --disable-sjlj-exceptions --disable-version-specific-runtime-libs = --enable-shared --build=3Di686-pc-linux --host=3Di686-pc-cygwin = --target=3Di686-pc-cygwin --enable-haifa --prefix=3D/usr = --exec-prefix=3D/usr --sysconfdir=3D/etc --libdir=3D/usr/lib = --includedir=3D/nonexistent/include --libexecdir=3D/usr/sbin=0A= Thread model: posix=0A= gcc version 3.2 20020927 (prerelease)=0A= ------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: application/octet-stream; name="Makefile" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Makefile" CFLAGS =3D -g=0A= EXT =3D .exe=0A= =0A= PROGS =3D static_function_ptr$(EXT)=0A= =0A= all: $(PROGS)=0A= =0A= static_function_ptr$(EXT): static_function_ptr_def.o = static_function_ptr.o=0A= $(CC) -o $@ static_function_ptr_def.o static_function_ptr.o $(LDFLAGS)=0A= =0A= clean:=0A= rm -f $(PROGS)=0A= rm -f *.o=0A= rm -f *.stackdump=0A= =0A= clean_editor:=0A= rm -f *~ *#=0A= =0A= clean_all: clean clean_editor=0A= =0A= =0A= ------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: application/octet-stream; name="static_function_ptr_def.h" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="static_function_ptr_def.h" #ifndef STATIC_FUNCTION_PTR_DEF_H=0A= #define STATIC_FUNCTION_PTR_DEF_H=0A= =0A= typedef void (*myFuncPtr) ();=0A= =0A= typedef struct {=0A= myFuncPtr ptr;=0A= } funcPtrStructDef;=0A= =0A= static funcPtrStructDef funcPtrStruct;=0A= =0A= #endif=0A= ------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: application/octet-stream; name="static_function_ptr_def.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="static_function_ptr_def.c" #include "static_function_ptr_def.h"=0A= =0A= void func() {=0A= printf("Here I am.\n");=0A= }=0A= =0A= static funcPtrStructDef funcPtrStruct =3D {func}; =0A= =0A= ------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: application/octet-stream; name="static_function_ptr.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="static_function_ptr.c" /* =0A= Test behavior of static function pointers with gcc in Win=0A= */=0A= #include <stdio.h>=0A= #include "static_function_ptr_def.h"=0A= =0A= int main() {=0A= =0A= printf("Try function directly...\n");=0A= func();=0A= =0A= printf("Try function via ptr...\n");=0A= funcPtrStruct.ptr();=0A= =0A= printf("Bye!\n");=0A= }=0A= =0A= =0A= ------=_NextPart_000_0004_01C35CFD.0BF988D0 Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ ------=_NextPart_000_0004_01C35CFD.0BF988D0--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |