Click here to Skip to main content
15,913,587 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: [edited] collision response in a RTS Pin
Calin Negru29-Aug-23 0:41
Calin Negru29-Aug-23 0:41 
GeneralRe: [edited] collision response in a RTS Pin
Randor 29-Aug-23 5:24
professional Randor 29-Aug-23 5:24 
AnswerRe: [edited] collision response in a RTS Pin
Gerry Schmitz30-Aug-23 10:52
mveGerry Schmitz30-Aug-23 10:52 
GeneralRe: [edited] collision response in a RTS Pin
Calin Negru31-Aug-23 6:05
Calin Negru31-Aug-23 6:05 
GeneralRe: [edited] collision response in a RTS Pin
Gerry Schmitz1-Sep-23 6:26
mveGerry Schmitz1-Sep-23 6:26 
GeneralRe: [edited] collision response in a RTS Pin
Calin Negru2-Sep-23 7:35
Calin Negru2-Sep-23 7:35 
GeneralRe: [edited] collision response in a RTS Pin
Gerry Schmitz3-Sep-23 5:30
mveGerry Schmitz3-Sep-23 5:30 
QuestionDSA Pin
ZAID razvi25-Aug-23 0:50
ZAID razvi25-Aug-23 0:50 
AnswerRe: DSA Pin
CPallini25-Aug-23 1:36
mveCPallini25-Aug-23 1:36 
GeneralRe: DSA Pin
ZAID razvi25-Aug-23 1:54
ZAID razvi25-Aug-23 1:54 
GeneralRe: DSA Pin
CPallini25-Aug-23 2:10
mveCPallini25-Aug-23 2:10 
GeneralRe: DSA Pin
ZAID razvi25-Aug-23 4:57
ZAID razvi25-Aug-23 4:57 
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 Pin
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 

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.