Consider:
void f(int i);
enum E {A};
int main(){
f(A); //cake will have a warning here
}
Consider:
void f(int i);
enum E {A};
int main(){
f(A); //cake will have a warning here
}
I will create a diagnostic in cake for this and others.
Basically I will respect the standard where it says enumerators are
int, but I will create a strict mode where this and other types of
conversion happens.
int main(){
f(true); //cake will have a warning here
f('A'); //not sure this one..
}
the same for enums.
On 11/02/2024 20:37, Kaz Kylheku wrote:
On 2024-02-11, Thiago Adams <thiago.adams@gmail.com> wrote:The problem is that enums often have to go through things which are
Consider:Why bother with enums that are stronger than in C++.
void f(int i);
enum E {A};
int main(){
f(A); //cake will have a warning here
}
Mainly, you don't want this:
void f(enum E);
f(42);
external to the program. For example they might be stored in a database
which is read by a parser which isn't written in C.
So they can't be
treated as entirely opaque and sometimes you do need to manipulate the values.
Em 2/12/2024 1:38 AM, Tim Rentsch escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
Consider:
void f(int i);
enum E {A};
int main(){
f(A); //cake will have a warning here
}
I will create a diagnostic in cake for this and others.
Basically I will respect the standard where it says enumerators are
int, but I will create a strict mode where this and other types of
conversion happens.
int main(){
f(true); //cake will have a warning here
f('A'); //not sure this one..
}
the same for enums.
This is comp.lang.c. Please take any discussions of languages
other than C to a venue where those discussions are topical,
such as comp.lang.misc.
Not sure what you mean.
This is about C and diagnostics.
For instance:
void f(int i);
int main()
{
f(true);
}
If a compiler emit a diagnostic "warning passing _Bool to integer" do
you think this is not C any more?
Thiago Adams <thiago.adams@gmail.com> writes:
[...]
In MISRA the concept is called "essential type"
a == b
The essential type of this expression is boolean.
I don't have access to the MISRA guidelines (they're not free),
but if that's what they say, it sounds like they're badly written.
(It's available for £15.00 from misra.org.uk. I'm almost, but not
quite, tempted to buy a copy.)
There's no C type called "boolean" unless you define it yourself.
The "essential type" they call "boolean" obviously isn't bool or
_Bool. It's not even a type in the C sense. And other posts here
have suggested that MISRA never actually defines what "essential
type" means.
Do the guidelines use the term "essential type" for "types" other
than "boolean"?
It just seems that the authors failed to think of the word
"condition", which would be a much clearer and more precise
description of what I presume they're trying to say. For example,
they could have written than any expression used as a condition
shall not be an assignment and shall not have an assignment as
any of its subexpressions, and anyone familiar with C would know
exactly what they mean. (The C standard doesn't define "condition",
but it would be easy to enumerate the contexts in which expressions
are treated as conditions, i.e., where a decision is made based on
whether the expression compares unequal to zero.)
Something related
https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/
"Different vendors have different warning sets and warning detection
logic, even if they support a common array of warning settings (such as
with GCC and Clang). Code that compiles with one toolchain warning-free
may not do so with another toolchain. We often see this with our
open-source projects. We primarily use Clang, and it is a common
occurrence that our CI server will report a warning when compiling our “warning-free” code with GCC."
Safety is not portable.
On 19/02/2024 20:06, Thiago Adams wrote:
Something related
https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/
"Different vendors have different warning sets and warning detection
logic, even if they support a common array of warning settings (such
as with GCC and Clang). Code that compiles with one toolchain
warning-free may not do so with another toolchain. We often see this
with our open-source projects. We primarily use Clang, and it is a
common occurrence that our CI server will report a warning when
compiling our “warning-free” code with GCC."
Safety is not portable.
The blog's reasoning is flawed.
A project build is dependent on three main things. The source code is one. The toolchain is another. And the build instructions - including toolchain flags and options, linker scripts, and perhaps things like the order of files passed to the linker. (It may also depend on things like
the time and day, if you use macros like __DATE__ and __TIME__, which is
an extraordinarily silly thing to have as a dependency.)
I often use DATE and TIME in my products to help indicate version.
It's not silly at all.
But it means the binary produced will be slightly different to one
generated 5 minutes earlier.
On 11/02/2024 16:27, Thiago Adams wrote:
Consider:
void f(int i);
enum E {A};
int main(){
f(A); //cake will have a warning here
}
I will create a diagnostic in cake for this and others.
Basically I will respect the standard where it says enumerators are
int, but I will create a strict mode where this and other types of
conversion happens.
It is interesting to note that treating warnings as errors is not
something new.
"The initial ISO C standard and its 1999 revision removed support for
many C language features that were widely known as sources of
application bugs due to accidental misuse. For backwards compatibility,
GCC 13 and earlier diagnosed use of these features as warnings only.
Although these warnings have been enabled by default for many releases, experience shows that these warnings are easily ignored, resulting in difficult to diagnose bugs. In GCC 14, these issues are now reported as errors, and no output file is created, providing clearer feedback to programmers that something is wrong. "
https://gcc.gnu.org/gcc-14/porting_to.html#c
On 19/02/2024 20:36, David Brown wrote:
On 19/02/2024 20:06, Thiago Adams wrote:
Something related
https://embeddedartistry.com/blog/2017/05/22/werror-is-not-your-friend/
"Different vendors have different warning sets and warning detection
logic, even if they support a common array of warning settings (such
as with GCC and Clang). Code that compiles with one toolchain
warning-free may not do so with another toolchain. We often see this
with our open-source projects. We primarily use Clang, and it is a
common occurrence that our CI server will report a warning when
compiling our “warning-free” code with GCC."
Safety is not portable.
The blog's reasoning is flawed.
A project build is dependent on three main things. The source code is
one. The toolchain is another. And the build instructions -
including toolchain flags and options, linker scripts, and perhaps
things like the order of files passed to the linker. (It may also
depend on things like the time and day, if you use macros like
__DATE__ and __TIME__, which is an extraordinarily silly thing to have
as a dependency.)
I often use DATE and TIME in my products to help indicate version.
It's not silly at all.
But it means the binary produced will be slightly different to one
generated 5 minutes earlier.
On 2024-02-19, bart <bc@freeuk.com> wrote:
I often use DATE and TIME in my products to help indicate version.
It's not silly at all.
But it means the binary produced will be slightly different to one
generated 5 minutes earlier.
The problem is that it's possible that the only difference is the
date and time. In which case it's the same program. Just the binary is gratuitously different.
Some GNU/Linux distros nowadays are obsessed with reproducibility:
meaning that whenver the same version of the same thing is built, all
the deliverables such as executables, PDF files or whatever else is bit
for bit identical to the previous runs.
This works even if if __DATE__ and __TIME__ are used; those get frozen.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 00:50:37 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,573 |