Thread View: comp.sys.ibm.pc.programmer
2 messages
2 total messages
Started by Michael Rice
Mon, 30 Jul 1990 05:02
Returning a char* in Turbo C:
Author: Michael Rice
Date: Mon, 30 Jul 1990 05:02
Date: Mon, 30 Jul 1990 05:02
45 lines
1436 bytes
1436 bytes
I wrote the following code to return a char* (a character pointer)
to a string let's say "Michigan". I went through the debugger and
the return value tempv->vname is correct but it returns something
else something like "\eu\r4" which is gibberish to me.
I am mainly calling it like this:
printf("%s",findvolname(temp));
where temp is a ENTRYPTR type... Any ideas what is wrong? I only have
problems when I try to return char*, not when I return integers or floats..
Any help is appreciated...
Here is the function:
#include "prog.h"
#include <stdio.h>
#include <dos.h>
extern VOLUMEPTR topvollist;
char *findvolname(enode)
ENTRYPTR enode;
{
VOLUMEPTR vtemp;
int done = 0;
vtemp = topvollist->nextvolume;
while(vtemp != NULL && !done)
{
if(vtemp->index == enode->volume_index)
{
done = 1;
}
else
{
vtemp = vtemp->nextvolume;
}
}
return(vtemp->vname);
}
Re: This can't be a TurboC bug can it?
Author: Tom Wiencko
Date: Wed, 01 Aug 1990 12:18
Date: Wed, 01 Aug 1990 12:18
36 lines
1450 bytes
1450 bytes
CRN@BYUVM.BITNET writes:
>I am having a VERY weird problem in TurboC. My code looks
>something like this:
>typedef struct{
> . . .
> char *str;
>int type;
>}FIELD;
>int proc(FIELD *fld)
>{
> . . .
> if(!valid_str(fld->str))
> return ERROR;
> . . .
>}
Turn off register optimization. There must be some code around the
function call which also uses the pointer - and with register optimization
turned on the compiler sometimes "forgets" which registers he has used
and which still have valid pointers in them.
Took me two days of intense debugging to find this, and it was confirmed
by Borland tech support. They also said that there is at this time no
fix for the problem.
I am not sure if Turbo C++ has the same bug - I have not tested it yet
(but I have left the optimization off...).
Tom
--
Tom Wiencko (w) (404) 977-4515
gatech!stiatl!tom Wiencko & Associates, Inc.
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