Re: canvas item color
- From: Erik Andersen <andersen inconnect com>
- To: Todd Graham Lewis <tlewis mindspring net>
- cc: gnome-list gnome org
- Subject: Re: canvas item color
- Date: Fri, 8 Jan 1999 10:51:08 -0700 (MST)
On Fri, 8 Jan 1999, Todd Graham Lewis wrote:
> On Fri, 8 Jan 1999, Federico Mena Quintero wrote:
>
> > In the meantime, you can do something like
> >
> > /* Colors are in the [0, 65535] range */
> > char *
> > get_color_spec (int r, int g, int b)
> > {
> > static char spec[50];
> >
> > sprintf (spec, "#%04x%04x%04x", r, g, b);
> > return spec;
> > }
> >
> > and use that as the color spec passed to the fill_color arguments.
> > You can modify it as appropriate for colors in the [0, 255] range.
>
> Question from Todd, the notoriously bad C programmer:
>
> Isn't this a memory leak? Shouldn't the caller be responsible for
> allocating spec[] and passing it in?
>
Nope. This is fine, since it is a static each call to this function
will return a pointer to the exact same spot in memory. Of course,
if this is in a threaded app, several threads could then be using the
same piece of memory at the same time...
The only way to make this into a memory leak would be to malloc
the char, and then return it w/o freeing it.
-Erik
--
Erik B. Andersen Web: http://www.inconnect.com/~andersen/
email: andersee@debian.org
--This message was written using 73% post-consumer electrons--
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]