count variable

count variable

by Mojdeh Akhavan -
Number of replies: 2

Hi,

I am trying to understand the behavior of firstmessage.c when I change the count variable in MPI_sSend and MPI_Recv commands. When I change it from 6 to 5 in MPI_Ssend (or in both Ssend and Recv), I get the following output:

1: Got message <Hello    Hello>
0: Sent message <Hello>

But if I make the same change for MPI_Recv, the result is:

1: Got message <>
0: Sent message <Hello>

Could you please explain it?


In reply to Mojdeh Akhavan

Re: count variable

by Bruno Mundim -
What you are seeing is language undefined behaviour, since you are trying
to print a C null-terminated string of character without the null character.
In other words you are not printing a C string and the behaviour is undefined
by the language standard. Some references on this topic:

https://en.wikipedia.org/wiki/Printf_format_string#Type_field
https://en.wikipedia.org/wiki/Null-terminated_string
https://wiki.sei.cmu.edu/confluence/display/c/STR32-C.+Do+not+pass+a+non-null-terminated+character+sequence+to+a+library+function+that+expects+a+string