[PATCH] Reports: Convert to C++

Alex White alex.white at oarcorp.com
Thu Jul 8 17:06:43 UTC 2021


On Wed, Jul 7, 2021 at 6:55 PM Chris Johns <chrisj at rtems.org> wrote:
>
> On 7/7/21 11:37 pm, Ryan Long wrote:
> > I'll get those pointers changed to references, and remove the whitespace changes. Is there a particular reason to not use '\n' instead of std::endl?
>
> Awesome and thanks.
>
> > I read that std::endl is slower since it's flushing the buffer each time that it is used.
>
> The std::endl is platform independent so language implementers can match it to
> the platform the code is being built for. It is similar to os.linesep in python
> and why that should be used there.

Chris,

I thought this, too, until Ryan forced me to look into it further. Thanks, Ryan :)

According to various sources, '\n' gets translated to the current platform's line separator as long as the C++ file stream is opened in text mode. See, for example, https://stackoverflow.com/a/213977.

So std::endl​ would indeed likely be slower AND unnecessary to achieve platform independence.

Alex
[https://cdn.sstatic.net/Sites/stackoverflow/Img/apple-touch-icon@2.png?v=73d79a89bded]<https://stackoverflow.com/a/213977>
"std::endl" vs "\\n"<https://stackoverflow.com/a/213977>
Many C++ books contain example code like this... std::cout << "Test line" << std::endl; ...so I've always done that too. But I've seen a lot of code from working developers like this
stackoverflow.com



>
> Chris
> _______________________________________________
> devel mailing list
> devel at rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20210708/0a7bfd86/attachment-0001.html>


More information about the devel mailing list