Welcome to the Linux Foundation Forum!

Lab Exercise incorrect conversion - some ambiguities

mpdse
mpdse Posts: 5
edited March 13 in LFD121 Class Forum

Hi,

About the example code snippet. I think there is a mistake, and the code will not do anything, but maybe I'm wrong?

/* The function signature of get_queue */
unsigned int get_queue(message** messages);

/* The part of our code which processes messages... /
B) _unsigned int queue_count = 0;_ B)
message
messages = malloc(sizeof(message) * MAX_MESSAGE_COUNT);

/* Process each message in order */
for (unsigned int i = 0; i < queue_count; i++) {
process_message(messages[i]);
}

I got the snippet below as a correct solution, although 0 does not make sense here. However, the change that needs to be made (int -> unsigned for queue_count) is the correct approach.

unsigned int queue_count = 0;

But for the whole code to work, it would need to be something like this, also swapped with the line below.

message* messages = malloc(sizeof(message) * MAX_MESSAGE_COUNT);
unsigned int queue_count = get_queue(messages);

BR

Comments

  • fcioanca
    fcioanca Posts: 2,250

    Hi @mpdse

    Thank you for your feedback. We have forwarded this to the course author.

    Regards,
    Flavia
    Linux Foundation Education

Categories

Upcoming Training