OpenQNX :: The QNX Community Portal

Jul 19, 2008 - 03:30 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 37 unlogged users and 1 registered user online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
micro
Post subject: conflicting types  PostPosted: May 16, 2007 - 04:15 PM
Senior Member


Joined: Jul 22, 2004
Posts: 327

conflicting types for ´someFunction´

struct sa0 {
int a;
int b;
}

struct sa1 {
int a;
int b;
}

void someFunction( int ia, int ib, struct sa0 bla0, struct sa1 bla1){
int someDecl;
struct sa2 bla2;

some Code here
.
.
.
}

This is a skel for all nonworking functions in our big project.
Somehow, while compiling with:
qcc -Vgcc_ntox86 -w8 -wapproto -O0 -g -I. -c -o output.o ../input.c
a lot of functions including structs in the functionheader, also defined via prototype (approto input.c > proto.h), result in an error i am not getting rid of.

conflicting types for `someFunction'

All Libs are present, everything else compiles fine.
The name is uniqe, also the struct names are uniqe.
all headers are present, everything works find but a lot of functions.

Somehow i think im missing something somewhere ...
 
 View user's profile Send private message  
Reply with quote Back to top
maschoen
Post subject: RE: conflicting types  PostPosted: May 16, 2007 - 07:19 PM
QNX Master


Joined: Jun 25, 2003
Posts: 1041

I don't have access to qcc right now, but I was able to run gcc.
I found that it didn't like three things in your example.
1) The structure definitions don't end with a ';'
2) The structure sa2 was undefined
3) someFunction() does not have a prototype

When I corrected these three things, the code compiled with gcc.
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
micro
Post subject: RE: conflicting types  PostPosted: May 16, 2007 - 09:43 PM
Senior Member


Joined: Jul 22, 2004
Posts: 327

The example was quite bad i think
1) they end with ; in normal code
2) they are all known
3) it has in proto.h ^^

And i guess there is the problem too, proto.h complains about the function already defined and input.c complains about the function having conflicting types.
Also when i try to auto-switch to the declaration of the struct, it points to the prototype in proto.h
But this behaviour is just within this some functions, all other 25 function in input.c work fine ...
 
 View user's profile Send private message  
Reply with quote Back to top
maschoen
Post subject: Re: RE: conflicting types  PostPosted: May 16, 2007 - 10:14 PM
QNX Master


Joined: Jun 25, 2003
Posts: 1041

I think a good place to start would be by creating and then posting some code that that by itself causes the problem. Often this exercise reveals the problem.
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
micro
Post subject: RE: Re: RE: conflicting types  PostPosted: May 23, 2007 - 01:23 PM
Senior Member


Joined: Jul 22, 2004
Posts: 327

I finally found a way to strip out the error, this code WON´T compile.
The problem is proto.h is included before the structure is defined (this worked fine with Watcom)
This makes producing the error conflicting types for the fuction itself and previous declaration for the prototype ..

And no it is not possible to include proto.h later in the source in production code, there are about 22k lines of code in this one file and about 2k lines of structures including ptr-to-functions etc.

test.c:
-------
#include <stdio.h>
#include <stdlib.h>

#include "proto.h"

struct ts3 {
int a;
int b;
};

int main(void){

struct ts3 sects3;

mytestfunc( &sects3 );
return 0;
}

void
mytestfunc( struct ts3 *ts3st ){
int i;
for( i=0; i<2; i++ ){
// big Do-Nothing-Loop, adepted from M$-Windoof
sleep(1);
}
}

---------------------------------------------

Makefile:
----------
CC = qcc
CXX = qcc
LD = qcc

CFLAGS = -w8 -wapproto -I.
CXXFLAGS = $(CFLAGS)
LDFLAGS = -Bstatic

#
# Application Program
#

all:
-rm -f ../proto.h
c:/Programme/QNX630/host/win32/x86/usr/photon/appbuilder/approto -p test.c > proto.h
$(CC) $(CXXFLAGS) -c -o test.o test.c
$(LD) test.o $(LDFLAGS) -M -o myApp

----------------------------------------------------------
 
 View user's profile Send private message  
Reply with quote Back to top
maschoen
Post subject: RE: Re: RE: conflicting types  PostPosted: May 23, 2007 - 02:04 PM
QNX Master


Joined: Jun 25, 2003
Posts: 1041

I haven't confirmed the example, but let me restate what you seem to be saying for clarification.

1) You have code where there are function declarations with pointers to structures that are defined later in the code.
2) This code won't compile either because of a GNU compiler quirk, or even possibly because the GNU compiler is correct.
3) This is annoying because the Watcom compiler didn't have this quirk

I didn't understand your reasoning for why you can't move the proto.h. Are you saying that it is impossible to move it,
or that you just don't want to?

Assuming this is all true, what kind of solution would hope for? A compiler fix or modification?
I suppose there might be some compiler flag that might help, since I have the GNU manual,
I'll take a look.
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
cburgess
Post subject: RE: Re: RE: conflicting types  PostPosted: May 23, 2007 - 02:29 PM
QNX Master


Joined: Aug 31, 2004
Posts: 180
Location: Ottawa
You need to forward declare your structures either in proto.h or before it.

ie

struct ts3;

#include <proto.h>

struct ts3 {
...
};
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
micro
Post subject: RE: Re: RE: conflicting types  PostPosted: May 23, 2007 - 02:50 PM
Senior Member


Joined: Jul 22, 2004
Posts: 327

It works fine with "prototyping" the structures too.
Thanks a lot.

To awnser your questen maschoen, no it was not possible to rearrange the proto.h-include or the structures,
since there are structuredefinition which have pointer to functions inside. This functions are prototyped in proto.h
but have the structure itself as parameter too (something like this^^). I already tried this for 5 days and was
very frustrated at every evening Very Happy
But that makes me even more happy now ... rm source.c && mv source.c.old source.c

Now only thing that is left is a sed or similar to automatically create a "protostruct.h" Smile
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.