C++ code formatting problems
-
I was hoping that someone would fix the C++ pretty printing code. In an ideal world, I would like to just embed plain C++ code in an article or answer:
#include
Currently; even pasting, and then choosing encode as HTML runs into problems:
#include <stdlib.h>
Yesterday I tried embedding some code in a reply, [The Lounge](https://www.codeproject.com/Messages/5813474/Re-Talk-about-demoralizing), and as all can see, this did not work all that well. Best regards Espen Harlinn
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
I was hoping that someone would fix the C++ pretty printing code. In an ideal world, I would like to just embed plain C++ code in an article or answer:
#include
Currently; even pasting, and then choosing encode as HTML runs into problems:
#include <stdlib.h>
Yesterday I tried embedding some code in a reply, [The Lounge](https://www.codeproject.com/Messages/5813474/Re-Talk-about-demoralizing), and as all can see, this did not work all that well. Best regards Espen Harlinn
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
I think you're supposed to use <pre lang=c++>...</pre>.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
I was hoping that someone would fix the C++ pretty printing code. In an ideal world, I would like to just embed plain C++ code in an article or answer:
#include
Currently; even pasting, and then choosing encode as HTML runs into problems:
#include <stdlib.h>
Yesterday I tried embedding some code in a reply, [The Lounge](https://www.codeproject.com/Messages/5813474/Re-Talk-about-demoralizing), and as all can see, this did not work all that well. Best regards Espen Harlinn
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
Thanks for the report. This, and the 'fix' by @David-ONeil in his response, my help us understand a tricky issue.
"Time flies like an arrow. Fruit flies like a banana."
-
Thanks for the report. This, and the 'fix' by @David-ONeil in his response, my help us understand a tricky issue.
"Time flies like an arrow. Fruit flies like a banana."
-
I think you're supposed to use <pre lang=c++>...</pre>.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.I was using:
<pre lang="C++">
</pre>Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
This has something to do with Markdown, as it happened to me earlier today when posting some Python code. And I never have Use Markdown formatting ticked.
That is my guess too … my gut feeling is that if markdown was disabled for anything between <pre ...> and </pre> then the problem will be solved.
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
Thanks for the report. This, and the 'fix' by @David-ONeil in his response, my help us understand a tricky issue.
"Time flies like an arrow. Fruit flies like a banana."
Great, I have been planning to write a couple of articles since February, so for me this is a real showstopper.
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
I was hoping that someone would fix the C++ pretty printing code. In an ideal world, I would like to just embed plain C++ code in an article or answer:
#include
Currently; even pasting, and then choosing encode as HTML runs into problems:
#include <stdlib.h>
Yesterday I tried embedding some code in a reply, [The Lounge](https://www.codeproject.com/Messages/5813474/Re-Talk-about-demoralizing), and as all can see, this did not work all that well. Best regards Espen Harlinn
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
I found that if your editor copies your code as something other than plain text (markup or whatever), like VS Code does, CP will have problems with pasting it into code panels. My workaround is to first paste into notepad to strip all the extra junk and then copy it from notepad to the site.
Real programmers use butterflies
-
I found that if your editor copies your code as something other than plain text (markup or whatever), like VS Code does, CP will have problems with pasting it into code panels. My workaround is to first paste into notepad to strip all the extra junk and then copy it from notepad to the site.
Real programmers use butterflies
That is probably worth an attempt …
#include
#include<std.lib>
'Use Markdown formatting' still interferes with how the text inside <pre>...</pre> element is interpreted, and so it seems like the solution I was looking for is rather simple: Uncheck 'Use Markdown formatting'. Hopefully this will also be the case for the article editor.
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
I was hoping that someone would fix the C++ pretty printing code. In an ideal world, I would like to just embed plain C++ code in an article or answer:
#include
Currently; even pasting, and then choosing encode as HTML runs into problems:
#include <stdlib.h>
Yesterday I tried embedding some code in a reply, [The Lounge](https://www.codeproject.com/Messages/5813474/Re-Talk-about-demoralizing), and as all can see, this did not work all that well. Best regards Espen Harlinn
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
Interestingly the issue was you had the "Use Markdown" checkbox checked. If you uncheck that, or use
```C++
...```
in Markdown, then it works fine. (I've edited your post to fix the formatting) Not sure what's going on, but it could be our Markdown processor (MarkdownSharp) doesn't like some of the character encoding.
cheers Chris Maunder
-
Interestingly the issue was you had the "Use Markdown" checkbox checked. If you uncheck that, or use
```C++
...```
in Markdown, then it works fine. (I've edited your post to fix the formatting) Not sure what's going on, but it could be our Markdown processor (MarkdownSharp) doesn't like some of the character encoding.
cheers Chris Maunder
Quote:
Interestingly the issue was you had the "Use Markdown" checkbox checked
Right, noticed that after Richards post. Unchecking 'Use Markdown' seems to work for most cases. Now, here is another, probably unrelated, formatting issue:
long long value = 1'000'000'000;
for(long long i = 0; i < value; ++i)
{
...
}and this would probably look better with a bit more color:
template
inline constexpr bool IsReference = std::is_same_v< std::remove_volatile_t> , std::remove_reference_t>>> == false;template
concept StreamIO = ( StreamReader && StreamWriter );template
concept StreamSeek = requires( T t, long long offset, SeekOrigin seekOrigin )
{
{ t.Seek( offset, seekOrigin ) }->std::convertible_to;
};template
concept StreamFeatureTests = requires( T t )
{
{ t.CanRead( ) } ->std::convertible_to;
{ t.CanSeek( ) } ->std::convertible_to;
{ t.CanTimeout( ) } ->std::convertible_to;
{ t.CanWrite( ) } ->std::convertible_to;
};But you are essentially right, unchecking 'Use Markdown' seems to do the trick :-)
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
Quote:
Interestingly the issue was you had the "Use Markdown" checkbox checked
Right, noticed that after Richards post. Unchecking 'Use Markdown' seems to work for most cases. Now, here is another, probably unrelated, formatting issue:
long long value = 1'000'000'000;
for(long long i = 0; i < value; ++i)
{
...
}and this would probably look better with a bit more color:
template
inline constexpr bool IsReference = std::is_same_v< std::remove_volatile_t> , std::remove_reference_t>>> == false;template
concept StreamIO = ( StreamReader && StreamWriter );template
concept StreamSeek = requires( T t, long long offset, SeekOrigin seekOrigin )
{
{ t.Seek( offset, seekOrigin ) }->std::convertible_to;
};template
concept StreamFeatureTests = requires( T t )
{
{ t.CanRead( ) } ->std::convertible_to;
{ t.CanSeek( ) } ->std::convertible_to;
{ t.CanTimeout( ) } ->std::convertible_to;
{ t.CanWrite( ) } ->std::convertible_to;
};But you are essentially right, unchecking 'Use Markdown' seems to do the trick :-)
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
Ugh. The apostrophe separated numbers are just...ugh. Comma separated, underscore separated. They are easy. But reusing a string delimiter for numbers means things get a little messy. I'll add the other case to our test rig and work out what's happening. I suspect the nest templates are blowing it's poor little brain.
cheers Chris Maunder
-
Quote:
Interestingly the issue was you had the "Use Markdown" checkbox checked
Right, noticed that after Richards post. Unchecking 'Use Markdown' seems to work for most cases. Now, here is another, probably unrelated, formatting issue:
long long value = 1'000'000'000;
for(long long i = 0; i < value; ++i)
{
...
}and this would probably look better with a bit more color:
template
inline constexpr bool IsReference = std::is_same_v< std::remove_volatile_t> , std::remove_reference_t>>> == false;template
concept StreamIO = ( StreamReader && StreamWriter );template
concept StreamSeek = requires( T t, long long offset, SeekOrigin seekOrigin )
{
{ t.Seek( offset, seekOrigin ) }->std::convertible_to;
};template
concept StreamFeatureTests = requires( T t )
{
{ t.CanRead( ) } ->std::convertible_to;
{ t.CanSeek( ) } ->std::convertible_to;
{ t.CanTimeout( ) } ->std::convertible_to;
{ t.CanWrite( ) } ->std::convertible_to;
};But you are essentially right, unchecking 'Use Markdown' seems to do the trick :-)
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
Workarounds for Code Project's Text Editor[^] :rolleyes: Although the one of SQL was fixed... I suppose I should edit it, but I am lazy ;P
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
Workarounds for Code Project's Text Editor[^] :rolleyes: Although the one of SQL was fixed... I suppose I should edit it, but I am lazy ;P
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
Thanks Nelek, I've seen it before :-)
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
Ugh. The apostrophe separated numbers are just...ugh. Comma separated, underscore separated. They are easy. But reusing a string delimiter for numbers means things get a little messy. I'll add the other case to our test rig and work out what's happening. I suspect the nest templates are blowing it's poor little brain.
cheers Chris Maunder
Here is the contents of a header file that seems to be causing some problems, as the preview does not show anything at all:
#pragma once
#ifndef __HCCPERSISTENT_H__
#define __HCCPERSISTENT_H__#include
#include
#include#pragma pack(push,1)
namespace Harlinn::Common::Core::Persistent
{
class TypeDescriptorCursor;/// /// A sequence is a variable length encoding where data of the same type /// is stored in blocks. Each block is of the same size (SequenceBlockSize = 8) /// and is trailed by a byte holding the number of used slots in the /// preceding block. The space not used by an element inside a bloc must /// be set to 0. A sequence ends with the first block that is not full, thus /// an empty sequence contains one block with all the bytes set to 0 and the /// trailing size byte set to 0. /// constexpr size\_t SequenceBlockSize = 8; /// /// The minimum number of bytes required to hold a valid /// type description /// constexpr size\_t MinimumValidTypeDescriptorDataSize = 4; enum class ModifierFlags : Byte { None, /// /// Indicates that type element is for an array of data. /// /// /// /// If used without the ::Fixed modifier, the data representation /// starts with a 7-bit encoded number specifying the number of elements /// in the array. /// /// /// If used with the ::Fixed modifier the lenght of the fixed-size /// follows immedeately after the TypeElementHeader as a 7-bit /// encoded number. /// /// Array = 0x01, /// /// Indicates a fixed number of elements /// Fixed = 0x02, /// /// Constant data trails the declaring type description element. /// /// /// If used together with the ::Array modifier, then the /// ::Fixed modifier must also be specified. /// Constant = 0x04, /// /// Indicates that the data is stored in big-endian /// format. /// BigEndian = 0x08, /// /// Indicates that the data is encoded in a way that al
-
Here is the contents of a header file that seems to be causing some problems, as the preview does not show anything at all:
#pragma once
#ifndef __HCCPERSISTENT_H__
#define __HCCPERSISTENT_H__#include
#include
#include#pragma pack(push,1)
namespace Harlinn::Common::Core::Persistent
{
class TypeDescriptorCursor;/// /// A sequence is a variable length encoding where data of the same type /// is stored in blocks. Each block is of the same size (SequenceBlockSize = 8) /// and is trailed by a byte holding the number of used slots in the /// preceding block. The space not used by an element inside a bloc must /// be set to 0. A sequence ends with the first block that is not full, thus /// an empty sequence contains one block with all the bytes set to 0 and the /// trailing size byte set to 0. /// constexpr size\_t SequenceBlockSize = 8; /// /// The minimum number of bytes required to hold a valid /// type description /// constexpr size\_t MinimumValidTypeDescriptorDataSize = 4; enum class ModifierFlags : Byte { None, /// /// Indicates that type element is for an array of data. /// /// /// /// If used without the ::Fixed modifier, the data representation /// starts with a 7-bit encoded number specifying the number of elements /// in the array. /// /// /// If used with the ::Fixed modifier the lenght of the fixed-size /// follows immedeately after the TypeElementHeader as a 7-bit /// encoded number. /// /// Array = 0x01, /// /// Indicates a fixed number of elements /// Fixed = 0x02, /// /// Constant data trails the declaring type description element. /// /// /// If used together with the ::Array modifier, then the /// ::Fixed modifier must also be specified. /// Constant = 0x04, /// /// Indicates that the data is stored in big-endian /// format. /// BigEndian = 0x08, /// /// Indicates that the data is encoded in a way that al
Espen Harlinn wrote:
They have, as you know, been a part of C++ for some time now, and they makes big numbers more readable: 1000000000000 vs 1'000'000'000'000 - while 1'0 is just silly compared to 10
He likes it with commas. 1'000'000'000'000 versus 1,000,000,000,000 Second one should not give formatting problems.
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
Espen Harlinn wrote:
They have, as you know, been a part of C++ for some time now, and they makes big numbers more readable: 1000000000000 vs 1'000'000'000'000 - while 1'0 is just silly compared to 10
He likes it with commas. 1'000'000'000'000 versus 1,000,000,000,000 Second one should not give formatting problems.
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
Quote:
Second one should not give formatting problems.
Since we are talking about code examples, my guess is that most people would expect them to compile …
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
-
Quote:
Second one should not give formatting problems.
Since we are talking about code examples, my guess is that most people would expect them to compile …
Espen Harlinn Senior Architect - Ulriken Consulting AS The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
Are you not asking too much? :rolleyes: :laugh: :laugh: :laugh:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.