LOGO
General Discussion Undecided where to post - do it here.

Reply to Thread New Thread
Old 08-23-2007, 09:12 PM   #1
mikapoq

Join Date
Oct 2005
Posts
469
Senior Member
Default C help needed
Try finishing that last line of code and closing your braces

And fix the includes?

edit: oh, the carets must be screwing stuff up.
mikapoq is offline


Old 08-23-2007, 09:17 PM   #2
RlUbQU3R

Join Date
Oct 2005
Posts
582
Senior Member
Default
Can't even upload a damn C file.
RlUbQU3R is offline


Old 08-23-2007, 09:19 PM   #3
mesZibeds

Join Date
Oct 2005
Posts
498
Senior Member
Default
Oh, and after a couple minutes I have no idea what's wrong.
mesZibeds is offline


Old 08-23-2007, 09:24 PM   #4
genna

Join Date
Oct 2005
Posts
432
Senior Member
Default
Originally posted by Kuciwalker
Oh, and after a couple minutes I have no idea what's wrong. As far as I can make out, the thing should work fine.
genna is offline


Old 08-23-2007, 09:36 PM   #5
HakSpeame

Join Date
Oct 2005
Posts
345
Senior Member
Default
You crazy Indian, you are writing to memory that isn't yours!

This offset:

(n-1)*l + m

Is going to be larger than the

(n-1)*(n-1)

you are allocating.

You can solve this much more elegantly without pointers BTW.
HakSpeame is offline


Old 08-23-2007, 09:53 PM   #6
ThisIsOK

Join Date
Oct 2005
Posts
515
Senior Member
Default
OK, I happen to have a Borland compiler around here, I'll compile this for you to see if I was right...
ThisIsOK is offline


Old 08-23-2007, 09:55 PM   #7
VewCoorkPow

Join Date
Oct 2005
Posts
408
Senior Member
Default
Originally posted by VetLegion
OK, I happen to have a Borland compiler around here, I'll compile this for you to see if I was right... I just checked.

It works.

And it compiles fine with gcc, you don't really need a Borland compiler.
VewCoorkPow is offline


Old 08-23-2007, 10:03 PM   #8
JulieSmithXIV

Join Date
Oct 2005
Posts
529
Senior Member
Default
And you always need a Borland compiler around dude!
JulieSmithXIV is offline


Old 08-23-2007, 10:59 PM   #9
justashonglefan

Join Date
Oct 2005
Posts
382
Senior Member
Default
Originally posted by VetLegion
Well the natural way would be array, saving you some calculation and being easier to read and slightly harder to mess up. I have to run, maybe I'll come back to this later and we can discuss your code Arrays are pointers
justashonglefan is offline


Old 08-23-2007, 11:05 PM   #10
Sleedyhex

Join Date
Oct 2005
Posts
396
Senior Member
Default
It should just segfault though...
Sleedyhex is offline


Old 08-23-2007, 11:50 PM   #11
nretdjuend

Join Date
Oct 2005
Posts
497
Senior Member
Default
Originally posted by Kuciwalker
It should just segfault though... No. The way it works is that the C lib for efficiency will allocate a big chunk of memory (one or more pages) at a time, and then give you little peices each time you call malloc.

The malloc implementation is free to use some of its allocated memory for control structures, for example a linked list of allocated memory. For example the elements of this list could be interspersed with the actual malloced memory.

So if you allocate 16 bytes, but write 20 to the pointer you get, you will, say, overwrite the linked list head of the following element in malloc's linked list. So when you call free() it will find an invalid data structure.

For debugging, and depending on the compiler, you can instruct the compiler to link against an alternative malloc implementation which is implemented to discover any corruption sooner.
nretdjuend is offline


Old 08-24-2007, 12:39 AM   #12
amimabremiBit

Join Date
Nov 2005
Posts
447
Senior Member
Default
Only a theoretician could say that pointers are arrays in such a context. And yes, I know that it's true
amimabremiBit is offline



Reply to Thread New Thread

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

All times are GMT +1. The time now is 06:59 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 PL2
Design & Developed by Amodity.com
Copyright© Amodity