Re: question about linker

Liste des GroupesRevenir à cl c  
Sujet : Re: question about linker
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.c
Date : 30. Nov 2024, 13:31:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vif0i9$1n911$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
Em 11/29/2024 5:53 PM, Keith Thompson escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
Em 11/28/2024 5:33 PM, Keith Thompson escreveu:
If an object is const because of its definition, then that object is
itself read-only, and anything that bypasses that (pointer casts, etc.)
causes undefined behavior.
>
Yes. This is my point. When the object itself cannot change, I used
the name immutable. And "ready only" when we don´t know if the object
is immutable or not - like pointer to const object.
In any, case it is just a matter of definition. I think it is clear
for both of us. (I am not claiming these definitions are part of C
standard)
>
For compile that computation what matters is the guarantee that the
compiler knows the values (it knows because it always the same value
of initialization) when using the object. (It does not depend on flow
analysis)
There's no requirement for the compiler to "know" the value of a const
object.
>
When the expression is required to be constant expression like in
switch case, then the compiler must know the value.
 True, but we weren't talking about constant expressions.  We were
talking about objects of const type.  Despite the obvious similarity of
the words "const" and "constant", they're really two different things.
 And the name of an object (in the absence of constexpr) can't be a
constant expression.  Given `const int zero = 0;`, the name `zero` is
not a constant expression and cannot be used in a case label.  (There
are proposals to change that.)
 
Sorry if I am begin repetitive, but here is my motivation to say that
const was already ready for that, no need to new keyword constexpr.
>
Consider this sample
>
void f(const int a)
{
   const int b = 1;
>
   switch (a){
      case a: break; // OPS
      case b: break; // should be OK
   }
}
>
The compiler does not know the value of 'a' even it is declared as
constant object; on the other hand the compiler knows the value of
'b';
>
So, here is my point - In init-declarators. const and constexpr
becomes similar.
 That has been proposed, but I personally oppose it, and the language (as
of C23) doesn't support it.  (C++ does.)
 Given:
      const int b = initializer;
 the expression `b` would be a constant expression if and only if the
initializer is a constant expression (optionally enclosed in {...}, I
suppose). 
Yes. Also compound literal could work like that. E.g
(const int) {1}
It's not always obvious whether an expression is constant or
not; you have to examine everything it refers to.
I think the compilers will check if the expression is constant anyway.

 And if you intend b
to be a constant expression but accidentally write a non-constant
initializer, it's still a perfectly valid declaration of a read-only
object initialized with the result of evaluating a run-time expression;
the error won't be flagged until you try to use it.
 Recall that `const int r = rand();` is still perfectly valid.
 
yes.

But given:
      constexpr int b = initializer;
 you *know* that b can be used as a constant expression, and if the
initializer is not constant the compiler will flag it immediately.
My guess is that compilers checks for constant expressions always even for non const. I just checked.
int main() {
   int i = 2147483647 * 2147483647;
}
GCC - warning: integer overflow in expression of type 'int' results in '1' [-Woverflow
CLANG - warning: overflow in expression; result is 1 with type 'int' [-Winteger-overflow]

This is already in C23.  Dropping constexpr is politically impossible at
this point.
Yes. But we can avoid it in new code if the same functionally is possible with const.

[...]
 
C23 also added constexpr in compound literal.
>
(constexpr struct X ){ }
>
I also don´t understand why not just use const for that.
 Because constexpr and const mean different things.
 
The difference for aggregates is that const can be used as constexpr if all initializers are constant expressions. (I don´t know what are the status of this in C2Y but this is just a logical consequence) While constexpr will check if all initializers are constant.
Apart of that I don´t see difference. Both can have storage for instance.

>
(static const struct X ){ }
>
I think in this case it makes sense.
 That's valid in C23.
 
I known.

Date Sujet#  Auteur
26 Nov 24 * question about linker382Thiago Adams
26 Nov 24 +* Re: question about linker16Thiago Adams
26 Nov 24 i`* Re: question about linker15Bart
26 Nov 24 i `* Re: question about linker14Thiago Adams
27 Nov 24 i  +* Re: question about linker2BGB
27 Nov 24 i  i`- Re: question about linker1Bart
27 Nov 24 i  +* Re: question about linker5David Brown
27 Nov 24 i  i`* Re: question about linker4Thiago Adams
27 Nov 24 i  i +* Re: question about linker2David Brown
27 Nov 24 i  i i`- Re: question about linker1Thiago Adams
2 Dec 24 i  i `- Re: question about linker1BGB
27 Nov 24 i  `* Re: question about linker6Michael S
27 Nov 24 i   `* Re: question about linker5Thiago Adams
27 Nov 24 i    `* Re: question about linker4Michael S
27 Nov 24 i     +- Re: question about linker1David Brown
28 Nov 24 i     +- Re: question about linker1Tim Rentsch
2 Dec 24 i     `- Re: question about linker1BGB
26 Nov 24 +* Re: question about linker20Bart
26 Nov 24 i`* Re: question about linker19Thiago Adams
26 Nov 24 i `* Re: question about linker18Bart
27 Nov 24 i  +* Re: question about linker3BGB
27 Nov 24 i  i`* Re: question about linker2fir
27 Nov 24 i  i `- Re: question about linker1BGB
27 Nov 24 i  `* Re: question about linker14Bart
27 Nov 24 i   +* Re: question about linker12Thiago Adams
27 Nov 24 i   i+- Re: question about linker1Thiago Adams
27 Nov 24 i   i`* Re: question about linker10Bart
27 Nov 24 i   i +* Re: question about linker6Bart
27 Nov 24 i   i i`* Re: question about linker5Thiago Adams
27 Nov 24 i   i i +* Re: question about linker3Thiago Adams
27 Nov 24 i   i i i`* Re: question about linker2Thiago Adams
27 Nov 24 i   i i i `- Re: question about linker1Bart
27 Nov 24 i   i i `- Re: question about linker1Bart
27 Nov 24 i   i `* Re: question about linker3Thiago Adams
27 Nov 24 i   i  `* Re: question about linker2Bart
27 Nov 24 i   i   `- Re: question about linker1Thiago Adams
28 Nov 24 i   `- Re: question about linker1Tim Rentsch
27 Nov 24 `* Re: question about linker345Waldek Hebisch
27 Nov 24  `* Re: question about linker344Thiago Adams
28 Nov 24   `* Re: question about linker343Keith Thompson
28 Nov 24    `* Re: question about linker342Thiago Adams
28 Nov 24     +* Re: question about linker337Bart
28 Nov 24     i`* Re: question about linker336Keith Thompson
29 Nov 24     i `* Re: question about linker335Bart
29 Nov 24     i  `* Re: question about linker334Keith Thompson
29 Nov 24     i   `* Re: question about linker333Bart
29 Nov 24     i    +* Re: question about linker3Keith Thompson
29 Nov 24     i    i`* Re: question about linker2Bart
29 Nov 24     i    i `- Re: question about linker1Keith Thompson
29 Nov 24     i    `* Re: question about linker329David Brown
29 Nov 24     i     `* Re: question about linker328Bart
29 Nov 24     i      +- Re: question about linker1Ike Naar
29 Nov 24     i      +* Re: question about linker325Michael S
29 Nov 24     i      i+* Re: question about linker322Bart
29 Nov 24     i      ii`* Re: question about linker321Michael S
29 Nov 24     i      ii +* Re: question about linker319David Brown
29 Nov 24     i      ii i`* Re: question about linker318Bart
29 Nov 24     i      ii i +* Re: question about linker164Keith Thompson
29 Nov 24     i      ii i i`* Re: question about linker163Bart
30 Nov 24     i      ii i i `* Re: question about linker162Keith Thompson
30 Nov 24     i      ii i i  +* Re: question about linker95Waldek Hebisch
30 Nov 24     i      ii i i  i+- Re: question about linker1Keith Thompson
30 Nov 24     i      ii i i  i+* Re: question about linker3James Kuyper
30 Nov 24     i      ii i i  ii`* Re: question about linker2Michael S
3 Dec 24     i      ii i i  ii `- Re: question about linker1Tim Rentsch
1 Dec 24     i      ii i i  i`* Re: question about linker90David Brown
1 Dec 24     i      ii i i  i +* Re: question about linker88Bart
1 Dec 24     i      ii i i  i i`* Re: question about linker87David Brown
1 Dec 24     i      ii i i  i i `* Re: question about linker86Bart
2 Dec 24     i      ii i i  i i  `* Re: question about linker85David Brown
2 Dec 24     i      ii i i  i i   `* Re: question about linker84Bart
2 Dec 24     i      ii i i  i i    +* Re: question about linker78David Brown
2 Dec 24     i      ii i i  i i    i+* Re: question about linker72Janis Papanagnou
2 Dec 24     i      ii i i  i i    ii+* Re: question about linker70Bart
2 Dec 24     i      ii i i  i i    iii+* Re: question about linker68David Brown
2 Dec 24     i      ii i i  i i    iiii`* Re: question about linker67Bart
3 Dec 24     i      ii i i  i i    iiii `* Re: question about linker66David Brown
3 Dec 24     i      ii i i  i i    iiii  +* Re: question about linker53Bart
3 Dec 24     i      ii i i  i i    iiii  i`* Re: question about linker52David Brown
3 Dec 24     i      ii i i  i i    iiii  i `* Re: question about linker51Bart
4 Dec 24     i      ii i i  i i    iiii  i  `* Re: question about linker50David Brown
4 Dec 24     i      ii i i  i i    iiii  i   `* Re: question about linker49Bart
4 Dec 24     i      ii i i  i i    iiii  i    `* Re: question about linker48David Brown
4 Dec 24     i      ii i i  i i    iiii  i     +* Re: question about linker24Bart
5 Dec 24     i      ii i i  i i    iiii  i     i`* Re: question about linker23David Brown
5 Dec 24     i      ii i i  i i    iiii  i     i +- Re: question about linker1Janis Papanagnou
5 Dec 24     i      ii i i  i i    iiii  i     i `* Re: question about linker21Bart
6 Dec 24     i      ii i i  i i    iiii  i     i  `* Re: question about linker20David Brown
6 Dec 24     i      ii i i  i i    iiii  i     i   `* Re: question about linker19Bart
6 Dec 24     i      ii i i  i i    iiii  i     i    +* Re: question about linker5Ike Naar
6 Dec 24     i      ii i i  i i    iiii  i     i    i+- Re: question about linker1Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i+- Re: question about linker1Keith Thompson
7 Dec 24     i      ii i i  i i    iiii  i     i    i`* Re: question about linker2Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i `- Re: question about linker1Keith Thompson
7 Dec 24     i      ii i i  i i    iiii  i     i    +* Re: question about linker10David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i`* Re: question about linker9Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i `* Re: question about linker8David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i  `* Re: question about linker7Bart
7 Dec 24     i      ii i i  i i    iiii  i     i    i   `* Re: question about linker6David Brown
7 Dec 24     i      ii i i  i i    iiii  i     i    i    `* Re: question about linker5Bart
8 Dec 24     i      ii i i  i i    iiii  i     i    i     +* Re: question about linker3Ben Bacarisse
8 Dec 24     i      ii i i  i i    iiii  i     i    i     `- Re: question about linker1David Brown
8 Dec 24     i      ii i i  i i    iiii  i     i    `* Re: question about linker3Waldek Hebisch
5 Dec 24     i      ii i i  i i    iiii  i     +* Re: question about linker15Waldek Hebisch
11 Dec 24     i      ii i i  i i    iiii  i     `* Re: question about linker8James Kuyper
3 Dec 24     i      ii i i  i i    iiii  `* Re: question about linker12Bart
3 Dec 24     i      ii i i  i i    iii`- Re: question about linker1Janis Papanagnou
2 Dec 24     i      ii i i  i i    ii`- Re: question about linker1Bart
2 Dec 24     i      ii i i  i i    i`* Re: question about linker5Bart
4 Dec 24     i      ii i i  i i    `* Re: question about linker5Waldek Hebisch
1 Dec 24     i      ii i i  i `- Re: question about linker1Janis Papanagnou
30 Nov 24     i      ii i i  +* Re: question about linker44Bart
30 Nov 24     i      ii i i  +- Re: question about linker1Janis Papanagnou
1 Dec 24     i      ii i i  `* Re: question about linker21David Brown
30 Nov 24     i      ii i `* Re: question about linker153David Brown
5 Dec 24     i      ii `- Re: question about linker1Tim Rentsch
30 Nov 24     i      i`* Re: question about linker2Tim Rentsch
29 Nov 24     i      `- Re: question about linker1David Brown
28 Nov 24     `* Re: question about linker4Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal