On Wed, Dec 18, 2024 at 10:51 AM Franco Martelli wrote:
>
> On 17/12/24 at 22:09, Jeffrey Walton wrote:
> > [...]
> > There may be one logic error in the code -- if you insert one item,
> > then you may double free the node because you free 'p' and then you
> > free 'last'.
> >
> > I would rewrite
On 17/12/24 at 22:09, Jeffrey Walton wrote:
On Tue, Dec 17, 2024 at 2:39 PM Franco Martelli wrote:
On 16/12/24 at 20:49, Jeffrey Walton wrote:
Here's the problem:
void dealloc()
{
for ( const DIGIT *p = first; p->next != NULL; p = p->next )
if ( p->prev != NULL )
On Wed, Dec 18, 2024 at 10:45:43AM +, Kevin Chadwick wrote:
> 18 Dec 2024 05:03:12 to...@tuxteam.de:
>
> > I'm all for concise code, but I usually revert some things in a second
> > pass when they seem to hurt clarity. After all, you write your code for
> > other people to read it.
>
> As you
18 Dec 2024 05:03:12 to...@tuxteam.de:
> I'm all for concise code, but I usually revert some things in a second
> pass when they seem to hurt clarity. After all, you write your code for
> other people to read it.
As you wrote the code then uness that second pass is weeks or months later then
cla
Franco Martelli writes:
> Peter A. Darnell, Philip E. Margolis - "C A Software Engineering Approach":
>
> https://www.google.it/books/edition/_/1nsS5q9aZOUC?hl=it&gbpv=0
>
> Do you have it too? It's pretty old, with some typo, but it looks to
> me good.
Sorry, no, doesn't look familiar. I rememb
On Tue, Dec 17, 2024 at 04:18:17PM -0500, Greg Wooledge wrote:
> On Tue, Dec 17, 2024 at 16:09:09 -0500, Jeffrey Walton wrote:
> > I would rewrite the cleanup code like so:
> >
> > void dealloc()
> > {
> > DIGIT *next, *p = head;
> > while( p )
> > next = p->nex
Hello :)
Le 17/12/2024 à 12:20, Anssi Saari a écrit :
Franco Martelli writes:
I'd prefer a mailing-list instead, once finished all the exercises,
I'd like to looking for somebody that he has my same handbook and to
ask him for exchange the exercises for comparison purpose.
Just curious, whi
On Tue, Dec 17, 2024 at 16:09:09 -0500, Jeffrey Walton wrote:
> I would rewrite the cleanup code like so:
>
> void dealloc()
> {
> DIGIT *next, *p = head;
> while( p )
> next = p->next, free( p ), p = next;
> }
The logic looks good, but I'm not a fan of thi
On Tue, Dec 17, 2024 at 2:39 PM Franco Martelli wrote:
>
> On 16/12/24 at 20:49, Jeffrey Walton wrote:
> > Here's the problem:
> >
> > void dealloc()
> > {
> > for ( const DIGIT *p = first; p->next != NULL; p = p->next )
> > if ( p->prev != NULL )
> > free( p->prev );
>
On 16/12/24 at 20:49, Jeffrey Walton wrote:
Here's the problem:
void dealloc()
{
for ( const DIGIT *p = first; p->next != NULL; p = p->next )
if ( p->prev != NULL )
free( p->prev );
free( last );
}
You seem to be checking backwards (p->prev) but walking the list
On 17/12/24 at 12:20, Anssi Saari wrote:
Franco Martelli writes:
I'd prefer a mailing-list instead, once finished all the exercises,
I'd like to looking for somebody that he has my same handbook and to
ask him for exchange the exercises for comparison purpose.
Just curious, which handbook is
Franco Martelli writes:
> I'd prefer a mailing-list instead, once finished all the exercises,
> I'd like to looking for somebody that he has my same handbook and to
> ask him for exchange the exercises for comparison purpose.
Just curious, which handbook is it?
Franco Martelli wrote:
...
> I'd prefer a mailing-list instead, once finished all the exercises, I'd
> like to looking for somebody that he has my same handbook and to ask him
> for exchange the exercises for comparison purpose.
> Does anybody know a mailing-list for C language questions?
comp
On 16/12/24 at 20:49, Jeffrey Walton wrote:
On Mon, Dec 16, 2024 at 2:22 PM Franco Martelli wrote:
I'm doing the exercises of a C language handbook. I'm using Valgrind to
check for memory leak since I use the malloc calls. In the past I was
used to using "valkyrie" but sadly isn't available an
On 16/12/24 at 20:42, Michael Kjörling wrote:
On 16 Dec 2024 17:21 +0100, from martelli...@gmail.com (Franco Martelli):
Put in something to count the number of calls to malloc() and free()
respectively. Don't forget calls outside of loops.
There isn't calls to malloc() or free() outside loops.
On 16/12/24 at 17:50, Greg Wooledge wrote:
On Mon, Dec 16, 2024 at 17:34:36 +0100, Franco Martelli wrote:
void dealloc()
{
for ( const DIGIT *p = head; p->next != NULL; p = p->next )
if ( p->prev != NULL )
free( p->prev );
free( last );
}
On Mon, Dec 16, 2024 at 2:22 PM Franco Martelli wrote:
>
> I'm doing the exercises of a C language handbook. I'm using Valgrind to
> check for memory leak since I use the malloc calls. In the past I was
> used to using "valkyrie" but sadly isn't available anymore for Bookworm
> (does anybody know
On 16 Dec 2024 17:21 +0100, from martelli...@gmail.com (Franco Martelli):
>> Put in something to count the number of calls to malloc() and free()
>> respectively. Don't forget calls outside of loops.
>
> There isn't calls to malloc() or free() outside loops. What do you mean?
>From a quick re-gla
On Mon, 16 Dec 2024 16:05:26 +0100
Franco Martelli wrote:
> I'm doing the exercises of a C language handbook.
By all means do the exercises in your handbook as a learning
experience. After that, I have found very useful Roger Sessions,
Reusable Data Structures For C, Prentice Hall (1989).
--
D
On Mon, Dec 16, 2024 at 17:34:36 +0100, Franco Martelli wrote:
> > > void dealloc()
> > > {
> > > for ( const DIGIT *p = head; p->next != NULL; p = p->next )
> > > if ( p->prev != NULL )
> > > free( p->prev );
> > > free( last );
> > > }
> >
> > I think you might ha
On 16/12/24 at 16:58, Greg Wooledge wrote:
On Mon, Dec 16, 2024 at 16:05:26 +0100, Franco Martelli wrote:
void add_element( unsigned int i )
{
DIGIT *p;
/* If the first element (the head) has not been
* created, create it now.
*/
if ( head == NULL )
On 16/12/24 at 16:43, Michael Kjörling wrote:
On 16 Dec 2024 16:05 +0100, from martelli...@gmail.com (Franco Martelli):
Is there a memory leak? What it sounds strange to me is that Valgrind
reports: "total heap usage: 9 allocs, 8 frees, …" when for me the calls to
"malloc" should be 8, not 9.
On Mon, Dec 16, 2024 at 16:05:26 +0100, Franco Martelli wrote:
> void add_element( unsigned int i )
> {
> DIGIT *p;
> /* If the first element (the head) has not been
> * created, create it now.
> */
> if ( head == NULL )
> {
> head = last = (DIGIT *
On 16 Dec 2024 16:05 +0100, from martelli...@gmail.com (Franco Martelli):
> Is there a memory leak? What it sounds strange to me is that Valgrind
> reports: "total heap usage: 9 allocs, 8 frees, …" when for me the calls to
> "malloc" should be 8, not 9.
Put in something to count the number of call
24 matches
Mail list logo