Mercurial > hg > xemacs-beta
comparison lwlib/xt-wrappers.h @ 4528:726060ee587c g++-warning-removal-2008-10-28
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
author | Stephen J. Turnbull <stephen@xemacs.org> |
---|---|
date | Wed, 29 Oct 2008 04:06:33 +0900 |
parents | |
children | 2ade80e8c640 |
comparison
equal
deleted
inserted
replaced
4524:03ba50f7ecd7 | 4528:726060ee587c |
---|---|
1 /* Wrappers for Xt functions and macros | |
2 | |
3 Copyright (C) 2008 Free Software Foundation | |
4 | |
5 This file is part of XEmacs. | |
6 | |
7 XEmacs is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
11 | |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 You should have received a copy of the GNU General Public License | |
17 along with XEmacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 Boston, MA 02111-1307, USA. */ | |
20 | |
21 /* Synched up with: Not in FSF. */ | |
22 | |
23 /* Original author: Stephen J. Turnbull for 21.5.29 */ | |
24 | |
25 /* Generic utility macros, including coping with G++ whining. | |
26 Used in lwlib via lwlib.h and X consoles via console-x.h. | |
27 | |
28 We would prefer to find another way to shut up G++. The issue is that | |
29 recent versions of the C++ standard deprecate implicit conversions | |
30 across function boundaries like | |
31 | |
32 typedef char *String; | |
33 void foo (String string); | |
34 foo ("bar"); | |
35 | |
36 because "bar" should be allowed to be a read-only array of chars. But of | |
37 course lots of legacy code (== X11) declares things as char * and expects | |
38 to assign literal strings to them. Now, the typedef in the example is | |
39 important because in G++ 4.3.2 at least, this | |
40 | |
41 void foo (const String string); | |
42 foo ("bar"); | |
43 | |
44 does not work as expected! G++ still warns about this construct. However, | |
45 if foo is declared | |
46 | |
47 void foo (const char *string); | |
48 | |
49 G++ does not complain. (#### There are two possibilities I can think of. | |
50 (a) G++ is buggy. (b) "const String" is interpreted as "char * const".) | |
51 | |
52 The upshot is that to avoid warnings with Xt's String typedef, we need to | |
53 arrange to cast literal strings to String, rather than use "const String" | |
54 in declarations. (My <X11/Intrinsic.h> says that the actual internal | |
55 typedef used is _XtString, so that String can be #define'd to something | |
56 else for the purposes of C++. But that doesn't really help us much.) | |
57 | |
58 It's not very satisfactory to do it this way -- it would be much better to | |
59 have const Strings where they make sense -- but it does eliminate a few | |
60 hundred warnings from the C++ build. And in any case we don't control the | |
61 many objects declared with String components in Intrinsic.h. The remaining | |
62 issues are the WEXTTEXT macro used in src/emacs.c, and Emacs.ad.h (where | |
63 instead of String we use const char * in src/event-Xt.c in the array that | |
64 #includes it). | |
65 */ | |
66 | |
67 #ifndef INCLUDED_xt_wrappers_h_ | |
68 #define INCLUDED_xt_wrappers_h_ | |
69 | |
70 /* Wrap XtResource, with the same elements as arguments. | |
71 The cast to String shuts up G++ 4.3's whining about const char *. | |
72 The invocation of sizeof should be pretty safe, and the cast to XtPointer | |
73 surely is, since that's how that member of XtResource is declared. It | |
74 doesn't hide potential problems, because XtPointer is a "generic" type in | |
75 any case -- the actual object will have a different type, that will be | |
76 cast to XtPointer. */ | |
77 | |
78 #define Xt_RESOURCE(name,_class,intrepr,type,member,extrepr,value) \ | |
79 { (String) name, (String) _class, (String) intrepr, sizeof(type), \ | |
80 member, extrepr, (XtPointer) value } | |
81 | |
82 /* Wrap XtSetArg, with the same arguments. | |
83 The cast to String shuts up G++ 4.3's whining about const char *. */ | |
84 | |
85 #define Xt_SET_ARG(al, resource, x) do { \ | |
86 XtSetArg ((al), (String) (resource), (x)); \ | |
87 } while (0) | |
88 | |
89 /* Convenience macros for getting/setting one resource value. */ | |
90 | |
91 #define Xt_SET_VALUE(widget, resource, value) do { \ | |
92 Arg al; \ | |
93 Xt_SET_ARG (al, resource, value); \ | |
94 XtSetValues (widget, &al, 1); \ | |
95 } while (0) | |
96 | |
97 #define Xt_GET_VALUE(widget, resource, location) do { \ | |
98 Arg al; \ | |
99 Xt_SET_ARG (al, resource, location); \ | |
100 XtGetValues (widget, &al, 1); \ | |
101 } while (0) | |
102 | |
103 #endif /* INCLUDED_xt_wrappers_h_ */ |