Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Date | 2011-11-16 13:13 -0500 |
|---|---|
| From | Kenneth Brody <kenbrody@spamcop.net> |
| Newsgroups | comp.lang.c |
| Subject | Re: Strange behaviour? |
| References | <ae447417-7ce0-420a-84be-620f6cbedf7d@p2g2000vbj.googlegroups.com> |
| Message-ID | <haGdnexi_tbTYF7TnZ2dnUVZ_sqdnZ2d@bestweb.net> (permalink) |
On 11/15/2011 2:31 PM, dmjcunha wrote:
> In the code below something odd happens when it is called with:
> merge (a[], lledge=13, lredge=15, lcedge=16, rcedge=17, rledge=18,
> rredge=19)
>
> I will post the gdb output to show the behaviour:
[...]
> 94 aux[rredge + rmid - rrj] = a[rrj + 1];
> (gdb) p rmid
> $5 = 18
> (gdb) s
> 93 for(rrj = rmid; rrj< rredge; rrj++)
> (gdb) p rmid
> $6 = 10<-------------- here I don't understand. There was no
> computation with rmid and it changed strangely to 10.
>
> A piece of the function I think you could help me:
>
> void merge(int a[], int lledge, int lredge, int lcedge, int rcedge,
> int rledge, int rredge)
> {
> int aux[N - 1], lmid, cmid, rmid, k;
[...]
> for(rrj = rmid; rrj< rredge; rrj++)
> aux[rredge + rmid - rrj] = a[rrj + 1];
[...]
Although elsethread you said that changing to "-O1" "solved" the problem,
all it did was hide it.
I would recommend going back to the compile flags in which the bug was
visible. Run that in the debugger again, and at the point that rmid is
about to "magically" change, check the values of N, rredge, rmid, and rrj.
You will probably see that redge+rmid-rj exceeds N-2, or is less than zero.
--
Kenneth Brody
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Strange behaviour? dmjcunha <dmjcunha@gmail.com> - 2011-11-15 11:31 -0800
Re: Strange behaviour? James Kuyper <jameskuyper@verizon.net> - 2011-11-15 14:43 -0500
Re: Strange behaviour? Seebs <usenet-nospam@seebs.net> - 2011-11-15 19:26 +0000
Re: Strange behaviour? dmjcunha <dmjcunha@gmail.com> - 2011-11-15 13:15 -0800
Re: Strange behaviour? Keith Thompson <kst-u@mib.org> - 2011-11-15 14:33 -0800
Re: Strange behaviour? Willem <willem@toad.stack.nl> - 2011-11-15 22:35 +0000
Re: Strange behaviour? dmjcunha <dmjcunha@gmail.com> - 2011-11-16 03:37 -0800
Re: Strange behaviour? Willem <willem@toad.stack.nl> - 2011-11-16 13:34 +0000
Re: Strange behaviour? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-16 06:07 -0800
Re: Strange behaviour? Kenneth Brody <kenbrody@spamcop.net> - 2011-11-16 13:13 -0500
Re: Strange behaviour? Kaz Kylheku <kaz@kylheku.com> - 2011-11-16 19:12 +0000
Re: Strange behaviour? dmjcunha <dmjcunha@gmail.com> - 2011-11-16 13:14 -0800
Re: Strange behaviour? Seebs <usenet-nospam@seebs.net> - 2011-11-16 22:18 +0000
csiph-web