Thread View: net.lang.c++
1 messages
1 total messages
Started by Brian Bershad
Sun, 14 Sep 1986 10:42
Standard C routines calling C++ (non-member) functions
Author: Brian Bershad
Date: Sun, 14 Sep 1986 10:42
Date: Sun, 14 Sep 1986 10:42
81 lines
2284 bytes
2284 bytes
I am running into a strange problem when linking in C++
code with Old C.
The following code shows what is happening:
/* THIS IS STANDARD C */
extern void foo();
main()
{
int x = 23;
foo(&x,&x);
}
----------------------------
/* THIS IS C++ */
#include <sys/types.h>
#include <sys/stat.h>
int lstat(char*, stat*);
void foo(int *x, int *y)
{
struct stat stbuf;
lstat("/etc/motd", &stbuf);
return;
}
------------------------------------
and they are compiled as:
% cc -c main.c
% CC -c foo.c main.o
When I write into &stbuf via the lstat, the foo's return
address seems to get clobbered, and the program core
dumps with an illegal instruction at the return statement,
with the values for x and y getting set to nil.
After many hours, I discovered that if I say
void foo(int *x, int *y)
{
struct stat* stbuf = new stat;
.....
delete stbuf;
return;
}
things will work.... granted, this is what I want to
do, but not how I want to say it.
More annoyingly, the following core dumps in ostream...
void foo(int* x, int* y)
{
cerr << *x;
cerr << *y;
}
when it is called from a C program (for reasons that are beyond
me... I can guess on the first example, but on this one, I have no
idea).
Since I am writing a fairly substantial package that uses
somebody else's RPC (with stubs generated in C) routines,
the fact that this stuff doesn't work is causing me numerous
headaches.
What is C++ expecting on the stack frame for non-member functions
that old C is not putting there???
Brian Bershad
University Washington Comp Sci
brian@uw-bluechip.arpa
bershad@ucbvax.berkeley.edu | ucbvax!bershad
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads