T.R | Title | User | Personal Name | Date | Lines |
---|
2141.1 | Need an example | WIBBIN::NOYCE | Pulling weeds, pickin' stones | Mon Apr 07 1997 17:30 | 12 |
| > [ I thought I declared it above main, outside of any sub-routine, i.e.
> global. ]
Well, for some reason the compiler didn't think so.
Can you show a short example of a source file that demonstrates the problem?
If the first time the compiler sees "struct s" is inside the function prototype,
then it declares the type "struct s" only for the duration of that prototype,
so you can't use the same type inside the function, and you can't use the same
type to call the function. (You can use a type that looks the same, but it
isn't "the same type.") But if you declare "struct s" before the function
prototype, its declaration lasts through to the end of the compilation.
|
2141.2 | Example | SBUOA::GUILLERMO | But the world still goes round and round | Mon Apr 07 1997 18:24 | 57 |
| re:.1
Hi,
>If the first time the compiler sees "struct s" is inside the function
prototype,
But the first time "struct s" is declared is before the declared
prototype.
>(You can use a type that looks the same, but it isn't "the same type.")
I understand this from the example I'm trying to follow in
"C - The complete reference" by Herbert Schild.
Here's a snapshot of what I'm trying to do:
/* Main module */
/* declarations */
char partinfo[42];
struct a_partrec {
char partno[12];
char remainder[30];
};
struct a_partrec partrec;
extern int sqlInsertPart( struct a_partrec partval );
int ExtractPartInfo( void );
unsigned int main(int argc, char *argv[])
{
strcpy( partinfo, argv[1] );
ExtractPartInfo();
sqlInsertPart( partrec );
}
int ExtractPartInfo()
{
/* copy partinfo to structure members e.g. partrec.partno */
}
[ Now in a separate .pc module which handles database I/O, the
module is defined]
int sqlInsertPart( struct a_partrec partval );
|
2141.3 | Compiler needs to see it first **in every compilation** | WIBBIN::NOYCE | Pulling weeds, pickin' stones | Mon Apr 07 1997 18:42 | 44 |
| > [ Now in a separate .pc module which handles database I/O, the
> module is defined]
>
> int sqlInsertPart( struct a_partrec partval );
You need to define struct a_partrec before this prototype too, either
in the same .pc file, or (better) in a .h file that's #include'd both
in tha main module and in the .pc file:
part.h:
=======
char partinfo[42];
struct a_partrec {
char partno[12];
char remainder[30];
};
main.c:
=======
#include "part.h"
struct a_partrec partrec;
extern int sqlInsertPart( struct a_partrec partval );
int ExtractPartInfo( void );
unsigned int main(int argc, char *argv[])
{
strcpy( partinfo, argv[1] );
ExtractPartInfo();
sqlInsertPart( partrec );
}
insert.pc:
==========
#include "part.h"
int sqlInsertPart( struct a_partrec partval );
|
2141.4 | | SBUOA::GUILLERMO | But the world still goes round and round | Mon Apr 07 1997 19:09 | 3 |
| Thanks much.
|
2141.5 | | SBUOA::GUILLERMO | But the world still goes round and round | Tue Apr 08 1997 14:32 | 9 |
| Here's another bonus for any fellow knowledge seekers out there.
I thought via another (painful) experience that you didn't need to
"null terminate" variables that were slated to be used in Oracle
expressions.
Well, you d**n sure need to null terminate them when using a structure,
otherwise, you wind up appending all sorts of unintended things to
your members. (oo-er).
|