Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #119853

Re: General Preference in C++

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c++
Subject Re: General Preference in C++
Date 2024-08-20 18:53 -0700
Organization None to speak of
Message-ID <87v7zubq07.fsf@nosuchdomain.example.com> (permalink)
References <va3fk7$ui68$1@paganini.bofh.team>

Show all headers | View raw


Jack <noreply@mandrill.com> writes:
> Do you guys have any preference in C++ to use something like this:
>
> constexpr size_t N = 12;
> #define N 12

The first N is of type size_t.  The second is of type int (the type of
the literal 12).

> constexpr is modern way of doing things but in terms of efficiency what 
> is the best way to do?

There is unlikely to be any difference in efficiency.

> You can then define an array like so:
>
> double numbers[N] {0};
>
> I wonder if you guys have anything to say about this.

I believe the general consensus (and my own preference) is to use core
language features rather than macros unless there's a very good reason
to use a macro.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

General Preference in C++ Jack <noreply@mandrill.com> - 2024-08-21 01:30 +0000
  Re: General Preference in C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-08-20 18:53 -0700
    Re: General Preference in C++ Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-08-22 13:18 -0400
      Re: General Preference in C++ scott@slp53.sl.home (Scott Lurndal) - 2024-08-22 17:54 +0000
        Re: General Preference in C++ Bonita Montero <Bonita.Montero@gmail.com> - 2024-08-22 20:08 +0200
        Re: General Preference in C++ David Brown <david.brown@hesbynett.no> - 2024-08-23 09:08 +0200
          Re: General Preference in C++ Chris Ahlstrom <OFeem1987@teleworm.us> - 2024-08-23 09:41 -0400
  Re: General Preference in C++ Andrey Tarasevich <andreytarasevich@hotmail.com> - 2024-08-20 20:07 -0700
    Re: General Preference in C++ David Brown <david.brown@hesbynett.no> - 2024-08-21 09:07 +0200
  Re: General Preference in C++ Bonita Montero <Bonita.Montero@gmail.com> - 2024-08-22 11:33 +0200

csiph-web