Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Site Bugs / Suggestions
  4. C++ code formatting problems

C++ code formatting problems

Scheduled Pinned Locked Moved Site Bugs / Suggestions
c++htmlcomhelp
18 Posts 7 Posters 25 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Espen Harlinn

    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

    M Offline
    M Offline
    Matthew Dennis
    wrote on last edited by
    #3

    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."

    L E 2 Replies Last reply
    0
    • M Matthew Dennis

      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."

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      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.

      E 1 Reply Last reply
      0
      • Greg UtasG Greg Utas

        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.

        E Offline
        E Offline
        Espen Harlinn
        wrote on last edited by
        #5

        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

        1 Reply Last reply
        0
        • L Lost User

          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.

          E Offline
          E Offline
          Espen Harlinn
          wrote on last edited by
          #6

          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

          1 Reply Last reply
          0
          • M Matthew Dennis

            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."

            E Offline
            E Offline
            Espen Harlinn
            wrote on last edited by
            #7

            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

            1 Reply Last reply
            0
            • E Espen Harlinn

              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

              honey the codewitchH Offline
              honey the codewitchH Offline
              honey the codewitch
              wrote on last edited by
              #8

              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

              E 1 Reply Last reply
              0
              • honey the codewitchH honey the codewitch

                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

                E Offline
                E Offline
                Espen Harlinn
                wrote on last edited by
                #9

                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

                1 Reply Last reply
                0
                • E Espen Harlinn

                  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

                  C Offline
                  C Offline
                  Chris Maunder
                  wrote on last edited by
                  #10

                  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

                  E 1 Reply Last reply
                  0
                  • C 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

                    E Offline
                    E Offline
                    Espen Harlinn
                    wrote on last edited by
                    #11

                    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

                    C N 2 Replies Last reply
                    0
                    • E Espen Harlinn

                      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

                      C Offline
                      C Offline
                      Chris Maunder
                      wrote on last edited by
                      #12

                      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

                      E 1 Reply Last reply
                      0
                      • E Espen Harlinn

                        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

                        N Offline
                        N Offline
                        Nelek
                        wrote on last edited by
                        #13

                        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.

                        E 1 Reply Last reply
                        0
                        • N Nelek

                          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.

                          E Offline
                          E Offline
                          Espen Harlinn
                          wrote on last edited by
                          #14

                          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

                          1 Reply Last reply
                          0
                          • C Chris Maunder

                            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

                            E Offline
                            E Offline
                            Espen Harlinn
                            wrote on last edited by
                            #15

                            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
                            
                            N 1 Reply Last reply
                            0
                            • E Espen Harlinn

                              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
                              
                              N Offline
                              N Offline
                              Nelek
                              wrote on last edited by
                              #16

                              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.

                              E 1 Reply Last reply
                              0
                              • N Nelek

                                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.

                                E Offline
                                E Offline
                                Espen Harlinn
                                wrote on last edited by
                                #17

                                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

                                N 1 Reply Last reply
                                0
                                • E Espen Harlinn

                                  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

                                  N Offline
                                  N Offline
                                  Nelek
                                  wrote on last edited by
                                  #18

                                  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.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups