Re: Whats the deal with 'const'?
- From: "lovecreatesbeauty" <lovecreatesbeauty@xxxxxxxxx>
- Date: 16 Jul 2006 08:08:20 -0700
Malcolm wrote:
The second problem is this
struct employee
{
char *name;
float salary;
};
void payroll(const employee *emp)
? void payroll(const employee **emp)
{
/* evil hacker */
strcpy(emp[0]->name, "Fred the Hacker");
? strcpy(emp->name, "Fred the Hacker");
pay(&emp[0]);
}
void payroll(const employee *emp);
In this case, the const keyword qualifies the object it points to as
constant. The object `name' is that one pointed by emp, so this is an
error:
/*(*emp).name = "C";*/
The object `*name' is pointed by name, not emp. That const does not
prevent following from being done:
*(*emp).name = 'c';
? void payroll(const employee **emp)
So does the const keyword applying to multiple-level pointer.
/*(**emp).name = "C";*/
*(**emp).name = 'c';
lovecreatesbeauty
.
- Follow-Ups:
- Re: Whats the deal with 'const'?
- From: Malcolm
- Re: Whats the deal with 'const'?
- References:
- Whats the deal with 'const'?
- From: Snis Pilbor
- Re: Whats the deal with 'const'?
- From: Malcolm
- Whats the deal with 'const'?
- Prev by Date: Re: Declaration specifiers
- Next by Date: Re: Newbie: learning to use malloc().
- Previous by thread: Re: Whats the deal with 'const'?
- Next by thread: Re: Whats the deal with 'const'?
- Index(es):
Relevant Pages
|