On Fri, Jan 29, 2016 at 07:13:00PM +0100, Magnus Fromreide wrote: > I just noticed that the C and C++ compiler output pointer types differently: > > Consider > > int i; > printf("%p", &i); > > When compiled as C that gives the warning > > format '%p' expects argument of type 'void *', but argument 2 has type 'int *' > > but when compiled as C++ it gives the warning > > format '%p' expects argument of type 'void*', but argument 2 has type 'int*' > > Why are they different?
So, C and C++ have different printers (C has c_tree_printer and C++ cp_printer). But in this case the difference comes from format_type_warning: 2657 p = (char *) alloca (pointer_count + 2); 2658 if (pointer_count == 0) 2659 p[0] = 0; 2660 else if (c_dialect_cxx ()) 2661 { 2662 memset (p, '*', pointer_count); 2663 p[pointer_count] = 0; 2664 } 2665 else 2666 { 2667 p[0] = ' '; 2668 memset (p + 1, '*', pointer_count); 2669 p[pointer_count + 1] = 0; 2670 } So the C FE gets the space but the C++ FE does not. The reason for this is probably to keep in sync with the C++ printer which doesn't put space before '*'; in dump_type_prefix we have 741 if (TYPE_PTR_P (t)) 742 pp_star (pp); so there's no pp_cxx_whitespace before '*'. I like the version with space more; maybe we could change this in the next stage1. Marek