Motivation sample:
struct X {
const char* const type;
};
struct X * make_x(){
struct X * p = malloc(sizeof *p);
if (p)
{
p->type = strdup("X"); // *** error, type is const ***
if (p->type == NULL)
{
free(p);
p = NULL;
}
}
return p; //ok
}
Em 4/24/2024 8:13 PM, Kaz Kylheku escreveu:
On 2024-04-24, Thiago Adams <thiago.adams@gmail.com> wrote:
Motivation sample:
struct X {
const char* const type;
};
struct X * make_x(){
struct X * p = malloc(sizeof *p);
if (p)
{
p->type = strdup("X"); // *** error, type is const ***
if (p->type == NULL)
{
free(p);
p = NULL;
}
}
return p; //ok
}
Different idea: allow all conversions without a cast which only
add qualifiers anywhere in the type:
struct X {
const char* const type;
};
struct mutable_X {
char* type;
};
In this case the types struct X and struct mutable_X are not
convertible. They are not the same type.
Now consider we have the keyword "mutable" that removes const from
struct members.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 154:10:09 |
Calls: | 10,383 |
Files: | 14,054 |
Messages: | 6,417,843 |