• Are you using C23 attributes?

    From Thiago Adams@thiago.adams@gmail.com to comp.lang.c on Mon Sep 8 09:10:22 2025
    From Newsgroup: comp.lang.c



    Are you using C23 attributes?

    If you answered yes: Is it directly or using a macro?


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From John McCue@jmclnx@SPAMisBADgmail.com to comp.lang.c on Mon Sep 8 14:43:01 2025
    From Newsgroup: comp.lang.c

    Thiago Adams <thiago.adams@gmail.com> wrote:

    Are you using C23 attributes?

    No and I will avoid it as much as I can.

    If you answered yes: Is it directly or using a macro?
    --
    [t]csh(1) - "An elegant shell, for a more... civilized age."
    - Paraphrasing Star Wars
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Thiago Adams@thiago.adams@gmail.com to comp.lang.c on Tue Sep 9 09:58:40 2025
    From Newsgroup: comp.lang.c

    On 9/8/2025 11:43 AM, John McCue wrote:
    Thiago Adams <thiago.adams@gmail.com> wrote:

    Are you using C23 attributes?

    No and I will avoid it as much as I can.

    If you answered yes: Is it directly or using a macro?


    I am using [[nodiscard]].
    First I did :

    #if __STDC_VERSION__ < 202311L
    #define NODISCARD
    #else
    #define NODISCARD [[nodiscard]]
    #endif

    NODISCARD int f();

    But then I changed to:

    #if __STDC_VERSION__ < 202311L
    #define _Attr(...)
    #else
    #define _Attr(...) [[ __VA_ARGS__ ]]
    #endif


    _Attr(nodiscard) int f();


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From David Brown@david.brown@hesbynett.no to comp.lang.c on Tue Sep 9 15:07:27 2025
    From Newsgroup: comp.lang.c

    On 08/09/2025 14:10, Thiago Adams wrote:


    Are you using C23 attributes?


    Not as yet - I haven't used C23 for real code yet.

    If you answered yes: Is it directly or using a macro?




    It would likely be via macros. I already use a number of gcc
    attributes, including ones that are the same or similar to C23
    attributes (like noreturn and const function attributes, etc.). I use
    these already via macros, since the gcc names are not always ideal
    (typically for historical reasons), and because macros let you easily
    adapt for different compilation environments.

    If and when C23 becomes prevalent, I might move to C23 attribute syntax.
    In the meantime, since gcc (and possibly some clang usage) is the
    compiler I use most, gcc attribute syntax works fine for my needs.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From David Brown@david.brown@hesbynett.no to comp.lang.c on Tue Sep 9 15:16:26 2025
    From Newsgroup: comp.lang.c

    On 09/09/2025 14:58, Thiago Adams wrote:
    On 9/8/2025 11:43 AM, John McCue wrote:
    Thiago Adams <thiago.adams@gmail.com> wrote:

    Are you using C23 attributes?

    No and I will avoid it as much as I can.

    If you answered yes: Is it directly or using a macro?


    I am  using [[nodiscard]].
    First I did :

    #if __STDC_VERSION__  < 202311L
    #define NODISCARD
    #else
    #define NODISCARD [[nodiscard]]
    #endif

    NODISCARD int f();

    But then I changed to:

    #if __STDC_VERSION__  < 202311L
    #define _Attr(...)
    #else
    #define _Attr(...) [[ __VA_ARGS__ ]]
    #endif


    _Attr(nodiscard) int f();




    Your first method is better if you want to be more flexible with tools.
    For example, gcc has "__attribute__((warn_unused_result))" which is,
    AFAICS, identical to C23's "[[nodiscard]]". Other compilers can have
    other methods - perhaps MSVC has a suitable "declspec".

    --- Synchronet 3.21a-Linux NewsLink 1.2