D15532: [Astyle] Add Objective C to list of languages with formatters

Aaron Puchert noreply at phabricator.kde.org
Fri Sep 21 01:09:31 BST 2018

aaronpuchert added inline comments.


> kossebau wrote in astyle_plugin.cpp:36
> For what I know, the days are still on-going due to this:
>   static const char * foo = "foo";
> is a non-const pointer to a const char array. You can do (accidentally)
>   foo = "bar";
> and the compiler will not see this runs against the (usual) intent.
> It is also one indirection more (unless the compiler is sure enough to be able to optimize this out), as `foo` is a symbol for a data that is a pointer, which holds the address of the char array.
> Where with
>   static const char foo[] = "foo";
> foo is a symbol for a data that is the char array.

The advice is mostly important for exported symbols, see Ulrich Drepper: How To Write Shared Libraries <https://www.akkadia.org/drepper/dsohowto.pdf>, section 2.4. For `static` (internal linkage) variables the compiler knows all references to the variable, so it can remove the indirection and see that it is const (if it is).

Nevertheless, it obviously doesn't hurt to get used to writing `char[]`, because sometimes it does matter.

By the way, even more modern would be `static constexpr char[]`.

> rjvbb wrote in astyle_plugin.cpp:377
> I know, I always add them anyway in my own code (just like I always add a default: with a break). Saves headscratching later on when you refactor and miss a missing break...

We could activate `-Wunreachable-code` so the compiler tells you where `break` isn't needed. With `-Wfallthrough` the compiler can detect unintended fallthroughs, so you wouldn't need to worry about a missing `break` either.

  R32 KDevelop


To: rjvbb, #kdevelop, kossebau, kfunk
Cc: aaronpuchert, kfunk, pino, kossebau, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20180921/64dae3c7/attachment-0001.html>

More information about the KDevelop-devel mailing list