Click here to Skip to main content
15,886,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DSA Pin
Richard Deeming28-Aug-23 21:34
mveRichard Deeming28-Aug-23 21:34 
GeneralRe: DSA Pin
ZAID razvi28-Aug-23 21:52
ZAID razvi28-Aug-23 21:52 
GeneralRe: DSA Pin
Andre Oosthuizen29-Aug-23 2:41
mveAndre Oosthuizen29-Aug-23 2:41 
GeneralRe: DSA Pin
Richard Deeming29-Aug-23 3:11
mveRichard Deeming29-Aug-23 3:11 
GeneralRe: DSA PinPopular
Richard MacCutchan28-Aug-23 21:56
mveRichard MacCutchan28-Aug-23 21:56 
GeneralRe: DSA Pin
Dave Kreskowiak29-Aug-23 2:04
mveDave Kreskowiak29-Aug-23 2:04 
GeneralRe: DSA Pin
Richard Deeming29-Aug-23 3:12
mveRichard Deeming29-Aug-23 3:12 
GeneralRe: DSA Pin
CPallini30-Aug-23 2:57
mveCPallini30-Aug-23 2:57 
Quote:
How is that possible sir! Second code is written by a renowned youtuber 'code_with_harry'.
I know. But here is renowed expert CPallini Big Grin | :-D .
If you run Harry's code using Valgrind, then you get (something similar to)
==3144== LEAK SUMMARY:
==3144==    definitely lost: 64 bytes in 4 blocks
==3144==    indirectly lost: 0 bytes in 0 blocks
==3144==      possibly lost: 0 bytes in 0 blocks
==3144==    still reachable: 0 bytes in 0 blocks
==3144==         suppressed: 0 bytes in 0 blocks
==3144== 
==3144== For lists of detected and suppressed errors, rerun with: -s
==3144== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)


On the other hand, if you run the following, alternative code
C
#include <stdio.h>
#include <stdlib.h>


struct Node
{
  int val;
  struct Node * next;
};


void traversal(const struct Node * p)
{
  printf("------------\n");
  while (p)
  {
    printf("%d ",p->val);
    p = p->next;
  }
  printf("\n------------\n");
}

// isEmpty is not strictly needed
// isFull is meaning-less

struct Node * enqueue(struct Node *p, int val)
{

  struct Node * prev = NULL;
  while (p)
  {
    prev = p;
    p = p->next;
  }
  p = malloc(sizeof(struct Node ));
  if ( p )
  {
    p->val = val;
    p->next = NULL;
    if ( prev )
      prev->next = p;
  }
  return p;
}

int dequeue(struct Node ** pp)
{
  int val = -1;
  struct Node * p = *pp;
  if ( p )
  {
    val = p->val;
    *pp = p->next;
    free(p);
  }
  return val;
}

int main()
{
  struct Node * ph = enqueue(NULL, 11);
  enqueue(ph, 22);
  enqueue(ph, 33);
  enqueue(ph, 44);
  traversal(ph);
  dequeue(&ph);
  dequeue(&ph);
  traversal(ph);
  dequeue(&ph);
  dequeue(&ph);
  return 0;
}

then Valgrind is somewhat happier:
==3153== HEAP SUMMARY:
==3153==     in use at exit: 0 bytes in 0 blocks
==3153==   total heap usage: 5 allocs, 5 frees, 1,088 bytes allocated
==3153== 
==3153== All heap blocks were freed -- no leaks are possible
==3153== 
==3153== For lists of detected and suppressed errors, rerun with: -s
==3153== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

"In testa che avete, Signor di Ceprano?"
-- Rigoletto

QuestionInvalid application of 'sizeof' to incomplete type 'struct Node' Pin
ZAID razvi22-Aug-23 20:20
ZAID razvi22-Aug-23 20:20 
AnswerRe: Invalid application of 'sizeof' to incomplete type 'struct Node' Pin
Victor Nijegorodov22-Aug-23 20:41
Victor Nijegorodov22-Aug-23 20:41 
GeneralRe: Invalid application of 'sizeof' to incomplete type 'struct Node' Pin
ZAID razvi24-Aug-23 23:45
ZAID razvi24-Aug-23 23:45 
AnswerRe: Invalid application of 'sizeof' to incomplete type 'struct Node' Pin
CPallini22-Aug-23 21:06
mveCPallini22-Aug-23 21:06 
PraiseRe: Invalid application of 'sizeof' to incomplete type 'struct Node' Pin
ThatsAlok23-Aug-23 17:01
ThatsAlok23-Aug-23 17:01 
GeneralOT Pin
CPallini23-Aug-23 19:59
mveCPallini23-Aug-23 19:59 
GeneralRe: Invalid application of 'sizeof' to incomplete type 'struct Node' Pin
ZAID razvi24-Aug-23 23:43
ZAID razvi24-Aug-23 23:43 
GeneralRe: Invalid application of 'sizeof' to incomplete type 'struct Node' Pin
CPallini24-Aug-23 23:47
mveCPallini24-Aug-23 23:47 
Questionconversions in 64 bit mode Pin
utcode21-Aug-23 18:35
utcode21-Aug-23 18:35 
AnswerRe: conversions in 64 bit mode Pin
CPallini21-Aug-23 20:41
mveCPallini21-Aug-23 20:41 
AnswerRe: conversions in 64 bit mode PinPopular
Randor 22-Aug-23 1:13
professional Randor 22-Aug-23 1:13 
GeneralRe: conversions in 64 bit mode Pin
utcode22-Aug-23 17:46
utcode22-Aug-23 17:46 
GeneralRe: conversions in 64 bit mode Pin
Richard MacCutchan22-Aug-23 21:42
mveRichard MacCutchan22-Aug-23 21:42 
Questiongenerate PDF file Pin
utcode18-Aug-23 18:13
utcode18-Aug-23 18:13 
AnswerRe: generate PDF file Pin
Victor Nijegorodov18-Aug-23 21:03
Victor Nijegorodov18-Aug-23 21:03 
AnswerRe: generate PDF file Pin
jschell21-Aug-23 2:37
jschell21-Aug-23 2:37 
QuestionGet LVN_MARQUEEBEGIN in CListCtrl Pin
Li Lin 202317-Aug-23 22:04
Li Lin 202317-Aug-23 22:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.