Waitrud Weber’s blog

things and reminders for memories

CodeAnalyzer: Code Block: It moves, which is still a wonder.

It moves, which is still a wonder if we comment out the print message like 012: as bold.

*

- - - -
       
  508 :char* m_concat( char *head, char *tail ) {
509 :    int nh, nt;
510 :    static int alloc = 0;
511 :    char* c_head;
512 :    char* result = NULL;
513 :    char* l_dummy_allocation_001 = NULL;
514 :
515 :    printf("char* m_concat( char *head, char *tail ) starts.\r\n");
516 :
517 :    nh = array_count( head );
518 :    nt = array_count( tail );
519 :    printf("array_count: %d %d | %s %s \r\n", nh, nt, head, tail);
520 :
521 :    for ( int j=0; j< 1000; j++ ) {
522 :        if ( alloc == 1 ) {
523 :            sleep(1000);
524 :        } else {
525 :            break;
526 :        }
527 :    }
528 :
529 :    if ( alloc == 0 ) {
530 :        alloc = 1;
531 :        for ( int i=0; i<100; i++) {
532 :            l_dummy_allocation_001 = (char *) malloc( sizeof(char) * ( nh + nt + 1 ) );
533 :            if ( l_dummy_allocation_001 != NULL ) break;
534 :
535 :            sleep(1);
536 :            char* d_a = (char *) malloc( 1 );
537 :            free(d_a);
538 :        }
539 :        alloc = 0;
540 :    }
541 :
542 :    if (l_dummy_allocation_001==NULL) {
543 :        printf("l_dummy_allocation_001 is null.\r\n");
544 :        exit(-1);
545 :    }
546 :
547 :    for( int i=0; i< nh; i++ ) {
548 :        *( l_dummy_allocation_001 + i ) = *(head + i);
549 :    }
550 :
551 :    for( int i=0; i< nt; i++ ) {
552 :        printf("function m_concat: i %d\r\n", i);
553 :        *( l_dummy_allocation_001 + nh + i ) = *(tail + i);
554 :    }
555 :
556 :    // 2 + 2 = 4 p[4] = "\n"
557 :    *( l_dummy_allocation_001 + nh + nt ) = '\0';
558 :    result = copyof_002 (l_dummy_allocation_001);
559 ://    put_memories( result );
560 :    printf("011: result|%p|=|%d| l_dummy_allocation_001|%p|=|%d|\r\n", result, array_count(result), l_dummy_allocation_001, array_count(l_dummy_allocation_001) );
561 :
562 :    free(l_dummy_allocation_001);
563 ://    printf("012: result|%p|=|%s| l_dummy_allocation_001|%p|\r\n", result, array_count(result), l_dummy_allocation_001 );
564 :
565 :    printf("char* m_concat( char *head, char *tail ) ends.\r\n");
566 :    return result;
567 :}
   
       
  > .\winmain_001.exe
char* m_concat( char *head, char *tail ) starts.
array_count: 3 3 | adc abc
function m_concat: i 0
function m_concat: i 1
function m_concat: i 2
char* copyof_002 ( char* str ) starts.
array_count 6
char* char_string_002 ( int num_memories ) starts. dummy_allocation_001=00000000
void print_memories_002 () starts.
void print_memories_002 () ends.
character i 0/10 num_memories 7 about|00000000|
dummy_allocation_001|00531150|
char** put_memories_002 ( char* str ) starts. index 0: index_max 0
char** put_memories_002 ( char* str ) ends.
char* char_string_002 ( int num_memories ) ends.
a_sleep_thread_002 starts.
a_sleep_thread_002 ends.
dummy_allocation_001 point|00531150|
str |00531140| dummy_allocation_001 |00531150|
char* copyof_002 ( char* str ) ends.
011: result|00531150|=|6| l_dummy_allocation_001|00531140|=|6|
char* m_concat( char *head, char *tail ) ends.
p_dummy_token|00531150|=|adcabc| p_dummy|00418248|=|abc|
void print_memories_002 () starts.
p|00531150|:dummy_ary[0]=|adcabc|
void print_memories_002 () ends.
   
  main.cpp  Wed Jul 13 18:09:29 2022
...
129 :int main ( int argc, char** argv ) {
130 :    char* p_dummy_token = "adc";
131 :    char* p_dummy = "abc";
132 :
133 :    p_dummy_token = m_concat( p_dummy_token, p_dummy );
134 :    printf("p_dummy_token|%p|=|%s| p_dummy|%p|=|%s|\r\n", p_dummy_token, p_dummy_token, p_dummy, p_dummy);
135 :    print_memories_002();
136 :
137 :    return 0;
138 :}
...
   

 

*

  - - -
-

wonder(noun)

Google
Cambridge Dictionary
"we all eat cakes from Gisella? she's a wonder"  
-      
-