This is the mail archive of the gcc@gcc.gnu.org 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 4/13/12, Chiheng Xu <chiheng.xu@gmail.com> wrote:
> On Apr 9, 2012, Richard Guenther <richard.guenther@gmail.com> 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);
> }

That approach will certainly work, but makes the correctness of
the assignment contingent on the condition being right.  If the
condition changes in appropriately, you can get a bug.  Even so,
I think what you suggest is a good intermediate step.

-- 
Lawrence Crowl


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