This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Switching to C++ by default in 4.8

On Mon, Apr 9, 2012 at 6:40 PM, Richard Guenther
<> wrote:
>> Certainly there are cases where the type must be made more specific,
>> and getting the wrong type here would necessarily be a dynamic check.
>> However, the number of dynamic checks can be substantially reduced.
>> To provide a specific example, suppose I have a common_decl *p and
>> need to do extra work if it is a var_decl.
>> do_general_work (p);
>> if (var_decl *q = p->to_var ())
>> {
>> Âdo_var_work_1 (q);
>> Âdo_var_work_2 (q);
>> Âdo_var_work_3 (q);
>> Âdo_var_work_4 (q);
>> }
>> The only dynamic work is in the pointer conversion. ÂAll other
>> function calls can be statically typed.
> Ok. ÂBut the above represents a completely different programming
> style than what we use currently. ÂWe do
> Âif (is_var_decl (p))
> Â Â{
> Â Â Â do_var_work_1 (p);
> ...
> Â Â}
> so what I was refering to was static errors we get when we are
> able to promote function argument / return types to more specific
> sub-classes.

What about this:
if(is_var_decl(p)) {
     var_decl * p_var_decl = (var_decl *) p;
     do_var_work_1 (p_var_decl);
}else if(is_type_decl(p)){
     type_decl * p_type_decl = (type_decl *) p;
     do_type_work_2 (p_type_decl);
}else if(is_field_decl(p)){
     field_decl * p_field_decl = (field_decl *) p;
     do_field_work_3 (p_field_decl);

Chiheng Xu

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]