Re: Troubles using Pro*C

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 24 Aug 2001 14:07:35 -0700
Message-ID: <9m6fmn01frq_at_drn.newsguy.com>


In article <9m6cbc$1f6$1_at_news.cec.uchile.cl>, =?ISO-8859-1?Q?=C1lvaro?= says...
>
>Hi everybody
>
>I´ve the next trouble in Pro*C.
>
>A function X is declared as:
>
>char *X(char *);
>
>but the problem is that, when I read the return value from X:
>
>sprintf(buffer,X(arg)) (with arg any string)
>
>I only get the first 16 character in buffer!!!! (X must return 26 or more
>characters)
>

post all of the code, we'll find the bug. It is C after all.

Make sure you aren't doing something as basic as this:

#include "stdio.h"

char * x( char * y )
{
char result[35];

    strcpy( result, "hello World, this works SOMETIMES" );     printf( "%d bytes = %s\n", strlen( result ), result );

    return result; /* this is a bug */
}

void main(int argc, char * argv[] )
{

    printf( "%s\n", x( "foo" ) );
}

(you know, returning an automatic local variable -- it goes out of scope).

>My question is: Is there any compilation flag related with this?
>Or is this simply a bug in Pro*C?
>
>In fact, if I replace my declaration of X, to a procedure
>
>X(arg,buffer)
>
>it works!!!! and returns the correct number of characters in buffer.
>
>Even more, if I print the return value of X (declared as a function) from
>inside X, I mean:
>
>char *X(char *arg)
>{
> ....
>
> printf("%s",RETURN_VALUE);
> return(RETURN_VALUE);
>
>}
>
>I got the correct number of characters in RETURN_VALUE, but the returned value
>is wrong!!!
>
>Thanks for your help
>
>I´m using Oracle 8.1.6 on an HP-UX 11.00 (64 bits)
>
>--
>Atte.
>Álvaro Palma Aste
>Grupo de Ing Biomédica - U. de Chile
>apalma_at_cipres.cec.uchile.cl.no.spam

--
Thomas Kyte (tkyte_at_us.oracle.com)             http://asktom.oracle.com/ 
Expert one on one Oracle, programming techniques and solutions for Oracle.
http://www.amazon.com/exec/obidos/ASIN/1861004826/  
Opinions are mine and do not necessarily reflect those of Oracle Corp 
Received on Fri Aug 24 2001 - 23:07:35 CEST

Original text of this message