🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.sgi.apps
3 messages
3 total messages Started by Eric Buddington Wed, 01 Nov 1995 21:48
CC problem: passing/receiving values to functions
#77
Author: Eric Buddington
Date: Wed, 01 Nov 1995 21:48
66 lines
2984 bytes
System: IRIX 5.3 on Indy, using SGI's CC and dbx

I compiled a program written in ANSI C using CC -g -cckr -fullwarn.
Most function calls work properly, but two have given me 
nexplainable errors:
---------------------------------------------------------------------
First: A function call that dosn't pass arguments correctly.
Quoted lines ( > ) are from the debugger.

>Process 25199 (r.in.dem) stopped at [main:112 ,0x404a58]

This is the call about to be executed:
>112  read_dem_record(record[0], 1, 1, dem_ascii);

Here are the values that *should* be passed:
>(dbx) print record[1], 1, 1, dem_ascii 
>0x100354d8 1 1 0xfb52914 

Now the function is called:
>(dbx) S
>[5] calling read_dem_record(record = (nil), row = 0, col = 0,
>   dem_ascii = (nil)) from function main
>Process 25171 (r.in.dem) stopped at [read_dem_record:83 +0xc,0x404fec]

Note that the arguments passed to the function are *not* the values in those
variables immediately before the call.
**In trying to replicate this once more to be certain, it passed the values
correctly.**

-----------------------------------------------------------------------
Second: A function returns values, but they aren't assigned as the program
specifies.
Again, dbx lines are quoted.

>[8] Process 25208 (r.in.dem) stopped at [conv_row_ll2u:85 ,0x405b68]

This is the call about to be executed:
>  85  cell_row[0] = G_northing_to_row(north, cell_head);

Again, the values that should be passed:
>(dbx) print north, cell_head
>4540683.5292848777 0x7fffad48 

This time, they are passed correctly, and the function returns 1441.0:
>(dbx) S
>[14] calling G_northing_to_row(north = 4540683.5292848777,
>   window = 0x7fffad48) from function conv_row_ll2u
>Process 25208 (r.in.dem) stopped at [G_northing_to_row:123 ,0x40d9c4]
> 123  return (window->north - north) / window->ns_res;
>(dbx) S
>[14] G_northing_to_row returning 1441.0 from G_northing_to_row
>Process 25208 (r.in.dem) stopped  [conv_row_ll2u:85 +0x18,0x405b80]
>  85  cell_row[0] = G_northing_to_row(north, cell_head);

But now the assignment goofs:
(dbx) S
>[13] cell_row[0] changed before [conv_row_ll2u: line 85]:
>                new value = 1.0;
>Process 25208 (r.in.dem) stopped on watchpoint writing address
>  0x7fffacd4 [conv_row_ll2u:85 +0x2c,0x405b94]
---------------------------------------------------------------------------
This has me (and a professor) completely stumped. If you have any answers
or suggestions, please email me at ebuddington@wesleyan.edu.

Thanks,
Eric Buddington
Re: CC problem: passing/receiving values to functions
#78
Author: Tanmoy Bhattacharya
Date: Wed, 01 Nov 1995 23:04
68 lines
3310 bytes
In article <478q02$d1o@news.wesleyan.edu>, eric@detritus (Eric Buddington)
writes: 
|> System: IRIX 5.3 on Indy, using SGI's CC and dbx
|> 
|> I compiled a program written in ANSI C using CC -g -cckr -fullwarn.
|> Most function calls work properly, but two have given me 
|> nexplainable errors:

Please post _complete_ short examples of your code: I would hazard a guess
that none of us try to debug a C code before looking at the source. Trying to
follow the ret of your post is an absolute waste of time.

(It is possible that the sgi compiler has a bug: in which case somebody will
recognize the symptoms. But, if that is what you are hoping for, why
crosspost to comp.lang.c????)

<snip>
|> This is the call about to be executed:
|> >112  read_dem_record(record[0], 1, 1, dem_ascii);
|> 
|> Here are the values that *should* be passed:
|> >(dbx) print record[1], 1, 1, dem_ascii 
|> >0x100354d8 1 1 0xfb52914 

I do not see why you thought 0 == 1. With logic like that, it is not
surprising that your code does not work ...

(Okay, okay, I am irritated because you expect us to be mind readers. But the
point is that if you are sending a post all over the world: please be very
careful about what you write!!!)

<snip>
|> **In trying to replicate this once more to be certain, it passed the values
|> correctly.**

Looks like you have uncovered an heisenbug :-) (`You cannot simultaneously
look for a bug and find it')

Seriously, this is usually a sign of memory corruption somewhere: try to
compile your program with all warnings turned on, _and_ do not ignore any
warning (You did not say whether there were any warnings). Check every memory
allocation and pointer use: it is impossible to say what the problem is from
what you have described.

|> 
|> -----------------------------------------------------------------------
|> Second: A function returns values, but they aren't assigned as the program
|> specifies.
|> Again, dbx lines are quoted.

Which are almost completely useless without more information. For all I know
you may not have declared G_northing_to_row, or misdeclared it. 

<snip>
|> This has me (and a professor) completely stumped. If you have any answers
|> or suggestions, please email me at ebuddington@wesleyan.edu.

As these are not answers nor concrete suggestions, I am not emailing them.

Cheers
Tanmoy
-- 
tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
<http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
Re: CC problem: passing/receiving values to functions
#79
Author: Paul Tomblin
Date: Thu, 02 Nov 1995 18:10
56 lines
2819 bytes
In a previous article, eric@detritus (Eric Buddington) said:
                       ^^^^^^^^^^^^^
By the way, your news software is badly configured and your return address is
invalid.

:
:This is the call about to be executed:
:>112  read_dem_record(record[0], 1, 1, dem_ascii);
:
:Here are the values that *should* be passed:
:>(dbx) print record[1], 1, 1, dem_ascii 
:>0x100354d8 1 1 0xfb52914 

Why are you passing record[0] and printing record[1]?  If you want to pass the
address of the array, don't pass the *value* of the first element.  If you are
doing what I think you are doing, I think you need to change the call to
read_dem_record(record, 1, 1, dem_ascii);

:This is the call about to be executed:
:>  85  cell_row[0] = G_northing_to_row(north, cell_head);
:
:Again, the values that should be passed:
:>(dbx) print north, cell_head
:>4540683.5292848777 0x7fffad48 
:
:This time, they are passed correctly, and the function returns 1441.0:
:>(dbx) S
:>[14] calling G_northing_to_row(north = 4540683.5292848777,
:>   window = 0x7fffad48) from function conv_row_ll2u
:>Process 25208 (r.in.dem) stopped at [G_northing_to_row:123 ,0x40d9c4]
:> 123  return (window->north - north) / window->ns_res;
:>(dbx) S
:>[14] G_northing_to_row returning 1441.0 from G_northing_to_row
:>Process 25208 (r.in.dem) stopped  [conv_row_ll2u:85 +0x18,0x405b80]
:>  85  cell_row[0] = G_northing_to_row(north, cell_head);
:
:But now the assignment goofs:
:(dbx) S
:>[13] cell_row[0] changed before [conv_row_ll2u: line 85]:
:>                new value = 1.0;
:>Process 25208 (r.in.dem) stopped on watchpoint writing address
:>  0x7fffacd4 [conv_row_ll2u:85 +0x2c,0x405b94]

For this one, I'd suggest you've got your prototypes and declarations screwed
up.  Do you have ansi style prototypes?  If so, is the prototype in scope when
you call the function, and is the function defined with a new style
declaration?  If not, have you properly defined the return type of the
function in the scope where you call it, and have you taken into account type
promotion in old-style argument passing?


-- 
Paul Tomblin, Contract Programmer.
I don't speak for Kodak, they don't speak for me.
(Email that is not work related should go to: ptomblin@canoe.com)
"You are in a twisty maze of Motif Widget resources, all inconsistent."
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