Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Preserve whitespace between code and comment doesn't?
Preserve whitespace between code and comment doesn't? [message #1739298] Fri, 29 July 2016 13:28 Go to next message
Will Lyons is currently offline Will LyonsFriend
Messages: 6
Registered: July 2014
Junior Member
Like the subject says, I have the "Windows->Preferences->C/C++->Code Style->Formatter->Comments->Preserve white space between code and line comments if possible" checkbox selected, but when I use Ctrl-Shift-F to run the formatter it shoves the comments right back against the code. I really love the auto-formatter correction, but this is enough of an issue that I'll have to stop using it entirely. Sad Is there some other option buried somewhere I need to configure to get this to actually work as advertised?

Eclipse Neon 4.6.0 CDT build id 20160613-18000
Using IAR SDK for ARM plugin 7.20.0.201605111150
Re: Preserve whitespace between code and comment doesn't? [message #1739309 is a reply to message #1739298] Fri, 29 July 2016 14:08 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Hi Will,

I suspect you have some unfortunate interaction between multiple formatting options. I have tried a few things and I cannot reproduce. Can you please provide more example of what fails? Perhaps with that I can reproduce and resolve the issue.

Thanks
Jonah
Re: Preserve whitespace between code and comment doesn't? [message #1739310 is a reply to message #1739309] Fri, 29 July 2016 14:18 Go to previous messageGo to next message
Will Lyons is currently offline Will LyonsFriend
Messages: 6
Registered: July 2014
Junior Member
Jonah:

typedef struct aglorithm1_storage_t
{
    float result[MAX_SIZE + 1]; //!< this is a comment! It explains what the variable is used for
    float epsilon;              //!< this is also a comment! Not quite as flashy but still important
    int32_t counter;            //!< me too! er, 3, oh whatever.  I'm important darnit
    float buffer[MAX_SIZE + 1]; //!< guess what I am... another unique snowflake, just like all the others
} aglorithm1_storage_t;


I'm thinking it has something to do with the print margin, because when I make that much bigger suddenly it doesn't move the comments. I thought somewhere there was an option to wrap comments to multiple lines but maybe I'm thinking of the Java version of Eclipse (which I use more often).
Re: Preserve whitespace between code and comment doesn't? [message #1739316 is a reply to message #1739310] Fri, 29 July 2016 14:39 Go to previous messageGo to next message
Will Lyons is currently offline Will LyonsFriend
Messages: 6
Registered: July 2014
Junior Member
Further investigation:
static const int32_t abcde = 100;       //!< this is some dummy text that
                                        //!< approximates the comment I used
gets the second line shoved to column 1... What the heck? Both lines are well within my print margin (set to 80) but I cannot get the second line not to move. And yet if I surround the declaration with curly braces then it preserves the second line's indentation. Of course I need the variable to have file scope, so this isn't an option, but another data point...
Re: Preserve whitespace between code and comment doesn't? [message #1739317 is a reply to message #1739316] Fri, 29 July 2016 14:45 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Great, I can reproduce the problem with the last code sample in a file by itself. Now lets see if I can figure out why!
Re: Preserve whitespace between code and comment doesn't? [message #1740314 is a reply to message #1739317] Thu, 11 August 2016 13:34 Go to previous messageGo to next message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
BTW I am submitting a fix for this for CDT 9.1 that is released with Neon.1 in a few weeks. Follow the bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=499553 if you want to see when you can get it in the nightly build.
Re: Preserve whitespace between code and comment doesn't? [message #1841567 is a reply to message #1739310] Thu, 20 May 2021 21:11 Go to previous message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 416
Registered: June 2014
Senior Member
Will Lyons wrote on Fri, 29 July 2016 15:18
Jonah:

typedef struct aglorithm1_storage_t
{
    float result[MAX_SIZE + 1]; //!< this is a comment! It explains what the variable is used for
    float epsilon;              //!< this is also a comment! Not quite as flashy but still important
    int32_t counter;            //!< me too! er, 3, oh whatever.  I'm important darnit
    float buffer[MAX_SIZE + 1]; //!< guess what I am... another unique snowflake, just like all the others
} aglorithm1_storage_t;


I'm thinking it has something to do with the print margin, because when I make that much bigger suddenly it doesn't move the comments. I thought somewhere there was an option to wrap comments to multiple lines but maybe I'm thinking of the Java version of Eclipse (which I use more often).


Your guess seems correct - as this sample works for me - but you have to set Maximum Line Width (in formatting settings -> Line Wrapping) to something big enough. For the sample in Comment 0 the comments exceed the 80 characters which is the default, so the whitespace is discarded.

This issue has resurfaced again recently and there may be more info in this bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=573674
Previous Topic:Can't install cmake4eclipse
Next Topic:How to index all header files in Eclipse CDT on linux?
Goto Forum:
  


Current Time: Thu Mar 28 12:16:54 GMT 2024

Powered by FUDForum. Page generated in 0.02767 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top