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
}
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;
};
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.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 919 |
Nodes: | 10 (1 / 9) |
Uptime: | 47:35:04 |
Calls: | 12,183 |
Calls today: | 3 |
Files: | 186,524 |
Messages: | 2,236,099 |