Re: char * vs. const char *
- From: Robert Wilhelm <robert physiol med tu-muenchen de>
- To: Federico Mena <federico nuclecu unam mx>
- Cc: gnome-list gnome org
- Subject: Re: char * vs. const char *
- Date: Wed, 4 Mar 1998 15:24:24 +0100
On Tue, Mar 03, 1998 at 01:46:53PM -0600, Federico Mena wrote:
> > Would it make sense to chage this to
> > gnome_pixmap_new_from_file (const char *filename) ?
> > Note that quite a few function iprototypes down to imlib would need to be changed.
>
> I wouldn't mind such a change. If you think it is useful, feel free
> to do it.
>
> Quartic
>
>
I have appended a patch. It would be nice if someone with cvs write access
could check it in.
Note that there are two new warnings are introduced with this patch:
gcc -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I./.. -I/usr/local/include -I/usr/X11R6/include -g -O2 -c -fPIC -DPIC gnome-pixmap.c
gnome-pixmap.c: In function `load_file':
gnome-pixmap.c:344: warning: passing arg 1 of `gdk_imlib_load_image' discards `const' from pointer target type
gnome-pixmap.c: In function `load_pixmap':
gnome-pixmap.c:494: warning: passing arg 2 of `g_hash_table_lookup' discards `const' from pointer target type
I will make a smilar patch to imlib soon to fix the first warning.
The second warning looks like a gcc flaw, because g_hash_table_lookup() takes
a const gpointer.
I have made a small test case. Maybe some C guru can comment on it.
snoopy$ cat g.c
typedef void* gpointer;
gpointer g (const gpointer);
gpointer g2 (const void *);
void f(const char *file)
{
gpointer pit;
pit = g ( file );
pit = g2( file );
}
snoopy$ gcc -c g.c
g.c: In function `f':
g.c:12: warning: passing arg 1 of `g' discards `const' from pointer target type
snoopy:~/SRC/gnome/work/gnome-libs/libgnomeui$
Robert
diff -ur cvs/gnome-libs/ChangeLog work/gnome-libs/ChangeLog
--- cvs/gnome-libs/ChangeLog Wed Mar 4 11:45:23 1998
+++ work/gnome-libs/ChangeLog Wed Mar 4 15:13:51 1998
@@ -1,3 +1,9 @@
+Wed Mar 4 15:12:59 1998 Robert Wilhelm <robert@snoopy.physiol.med.tu-muenchen.de>
+
+ * libgnome/gnome-util.h:
+ * libgnome/gnome-util.c:
+ (g_file_exists): added const to parameter.
+
Wed Mar 4 01:06:58 1998 Tom Tromey <tromey@cygnus.com>
* acconfig.h (HAVE_PROGRAM_INVOCATION_SHORT_NAME,
diff -ur cvs/gnome-libs/libgnome/gnome-util.c work/gnome-libs/libgnome/gnome-util.c
--- cvs/gnome-libs/libgnome/gnome-util.c Tue Mar 3 10:10:20 1998
+++ work/gnome-libs/libgnome/gnome-util.c Wed Mar 4 14:23:16 1998
@@ -119,11 +119,11 @@
return (gnome_dirrelative_file (GNOMEDATADIR, "share", filename, TRUE));
}
-/* DOC: g_file_exists (char *filename)
+/* DOC: g_file_exists (const char *filename)
* Returns true if filename exists
*/
int
-g_file_exists (char *filename)
+g_file_exists (const char *filename)
{
struct stat s;
diff -ur cvs/gnome-libs/libgnome/gnome-util.h work/gnome-libs/libgnome/gnome-util.h
--- cvs/gnome-libs/libgnome/gnome-util.h Tue Mar 3 10:10:20 1998
+++ work/gnome-libs/libgnome/gnome-util.h Wed Mar 4 14:23:38 1998
@@ -12,7 +12,7 @@
char *gnome_unconditional_libdir_file (char *filename);
char *gnome_unconditional_datadir_file (char *filename);
char *gnome_unconditional_pixmap_file (char *filename);
-int g_file_exists (char *filename);
+int g_file_exists (const char *filename);
char *g_copy_strings (const char *first, ...);
char *g_unix_error_string (int error_num);
char *g_concat_dir_and_file (const char *dir, const char *file);
diff -ur cvs/gnome-libs/libgnomeui/ChangeLog work/gnome-libs/libgnomeui/ChangeLog
--- cvs/gnome-libs/libgnomeui/ChangeLog Wed Mar 4 11:45:29 1998
+++ work/gnome-libs/libgnomeui/ChangeLog Wed Mar 4 15:12:39 1998
@@ -1,3 +1,18 @@
+Wed Mar 4 15:03:52 1998 Robert Wilhelm <robert@physiol.med.tu-muenchen.de>
+
+ * gnome-pixmap.h:
+ * gnome-pixmap.c: (gnome_pixmap_new_from_file): added const
+ to filename parameter.
+ (gnome_pixmap_new_from_file_at_size): Likewise.
+ (load_file): Likewise.
+ (gnome_pixmap_load_file): Likewise.
+ (gnome_pixmap_load_file_at_size): Likewise.
+ (load_pixmap): Likewise.
+ (gnome_create_pixmap_gdk): Likewise.
+ (gnome_create_pixmap_gtk): Likewise.
+ (gnome_create_pixmap_widget): Likewise.
+ (gnome_set_pixmap_widget): Likewise.
+
Wed Mar 4 00:14:01 1998 Miguel de Icaza <miguel@nuclecu.unam.mx>
* gtk-ted.c (gtk_ted_new_layout): create widgets with an argument
diff -ur cvs/gnome-libs/libgnomeui/gnome-pixmap.c work/gnome-libs/libgnomeui/gnome-pixmap.c
--- cvs/gnome-libs/libgnomeui/gnome-pixmap.c Sun Mar 1 17:40:45 1998
+++ work/gnome-libs/libgnomeui/gnome-pixmap.c Wed Mar 4 13:35:46 1998
@@ -109,7 +109,7 @@
}
GtkWidget *
-gnome_pixmap_new_from_file (char *filename)
+gnome_pixmap_new_from_file (const char *filename)
{
GnomePixmap *gpixmap;
@@ -120,7 +120,7 @@
}
GtkWidget *
-gnome_pixmap_new_from_file_at_size (char *filename, int width, int height)
+gnome_pixmap_new_from_file_at_size (const char *filename, int width, int height)
{
GnomePixmap *gpixmap;
@@ -335,7 +335,7 @@
}
static void
-load_file (GnomePixmap *gpixmap, char *filename, int scaled, int width, int height)
+load_file (GnomePixmap *gpixmap, const char *filename, int scaled, int width, int height)
{
GdkImlibImage *im;
@@ -370,7 +370,7 @@
}
void
-gnome_pixmap_load_file (GnomePixmap *gpixmap, char *filename)
+gnome_pixmap_load_file (GnomePixmap *gpixmap, const char *filename)
{
g_return_if_fail (gpixmap != NULL);
g_return_if_fail (GNOME_IS_PIXMAP (gpixmap));
@@ -380,7 +380,7 @@
}
void
-gnome_pixmap_load_file_at_size (GnomePixmap *gpixmap, char *filename, int width, int height)
+gnome_pixmap_load_file_at_size (GnomePixmap *gpixmap, const char *filename, int width, int height)
{
g_return_if_fail (gpixmap != NULL);
g_return_if_fail (GNOME_IS_PIXMAP (gpixmap));
@@ -485,7 +485,7 @@
}
static void
-load_pixmap(GdkWindow *window, GdkPixmap **pixmap, GdkBitmap **mask, GdkColor *transparent, char *filename)
+load_pixmap(GdkWindow *window, GdkPixmap **pixmap, GdkBitmap **mask, GdkColor *transparent, const char *filename)
{
struct pixmap_item *pit;
@@ -505,7 +505,7 @@
}
void
-gnome_create_pixmap_gdk (GdkWindow *window, GdkPixmap **pixmap, GdkBitmap **mask, GdkColor *transparent, char *file)
+gnome_create_pixmap_gdk (GdkWindow *window, GdkPixmap **pixmap, GdkBitmap **mask, GdkColor *transparent, const char *file)
{
g_assert(window != NULL);
g_assert(pixmap != NULL);
@@ -522,7 +522,7 @@
}
void
-gnome_create_pixmap_gtk (GtkWidget *window, GdkPixmap **pixmap, GdkBitmap **mask, GtkWidget *holder, char *file)
+gnome_create_pixmap_gtk (GtkWidget *window, GdkPixmap **pixmap, GdkBitmap **mask, GtkWidget *holder, const char *file)
{
GtkStyle *style;
@@ -567,7 +567,7 @@
}
GtkWidget *
-gnome_create_pixmap_widget (GtkWidget *window, GtkWidget *holder, char *file)
+gnome_create_pixmap_widget (GtkWidget *window, GtkWidget *holder, const char *file)
{
GdkPixmap *pixmap;
GdkBitmap *mask;
@@ -592,7 +592,7 @@
}
void
-gnome_set_pixmap_widget (GtkPixmap *pixmap, GtkWidget *window, GtkWidget *holder, gchar *file)
+gnome_set_pixmap_widget (GtkPixmap *pixmap, GtkWidget *window, GtkWidget *holder, const char *file)
{
GdkPixmap *gpixmap;
GdkBitmap *mask;
diff -ur cvs/gnome-libs/libgnomeui/gnome-pixmap.h work/gnome-libs/libgnomeui/gnome-pixmap.h
--- cvs/gnome-libs/libgnomeui/gnome-pixmap.h Tue Feb 24 05:40:09 1998
+++ work/gnome-libs/libgnomeui/gnome-pixmap.h Wed Mar 4 13:35:50 1998
@@ -31,8 +31,8 @@
guint gnome_pixmap_get_type (void);
-GtkWidget *gnome_pixmap_new_from_file (char *filename);
-GtkWidget *gnome_pixmap_new_from_file_at_size (char *filename, int width, int height);
+GtkWidget *gnome_pixmap_new_from_file (const char *filename);
+GtkWidget *gnome_pixmap_new_from_file_at_size (const char *filename, int width, int height);
GtkWidget *gnome_pixmap_new_from_xpm_d (char **xpm_data);
GtkWidget *gnome_pixmap_new_from_xpm_d_at_size (char **xpm_data, int width, int height);
GtkWidget *gnome_pixmap_new_from_rgb_d (unsigned char *data, unsigned char *alpha,
@@ -41,8 +41,8 @@
int rgb_width, int rgb_height,
int width, int height);
-void gnome_pixmap_load_file (GnomePixmap *gpixmap, char *filename);
-void gnome_pixmap_load_file_at_size (GnomePixmap *gpixmap, char *filename, int width, int height);
+void gnome_pixmap_load_file (GnomePixmap *gpixmap, const char *filename);
+void gnome_pixmap_load_file_at_size (GnomePixmap *gpixmap, const char *filename, int width, int height);
void gnome_pixmap_load_xpm_d (GnomePixmap *gpixmap, char **xpm_data);
void gnome_pixmap_load_xpm_d_at_size (GnomePixmap *gpixmap, char **xpm_data, int width, int height);
void gnome_pixmap_load_rgb_d (GnomePixmap *gpixmap, unsigned char *data, unsigned char *alpha,
@@ -63,12 +63,12 @@
GdkPixmap **pixmap,
GdkBitmap **mask,
GdkColor *transparent,
- char *file);
+ const char *file);
void gnome_create_pixmap_gtk (GtkWidget *window,
GdkPixmap **pixmap,
GdkBitmap **mask,
GtkWidget *holder,
- char *file);
+ const char *file);
void gnome_create_pixmap_gtk_d (GtkWidget *window,
GdkPixmap **pixmap,
GdkBitmap **mask,
@@ -76,14 +76,14 @@
char **data);
GtkWidget *gnome_create_pixmap_widget (GtkWidget *window,
GtkWidget *holder,
- char *file);
+ const char *file);
GtkWidget *gnome_create_pixmap_widget_d (GtkWidget *window,
GtkWidget *holder,
char **data);
void gnome_set_pixmap_widget (GtkPixmap *pixmap,
GtkWidget *window,
GtkWidget *holder,
- char *file);
+ const char *file);
void gnome_set_pixmap_widget_d (GtkPixmap *pixmap,
GtkWidget *window,
GtkWidget *holder,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]