All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] "_ENTRY" is both a struct and a typedef?
@ 2016-09-08 16:31 Robert P. J. Day
  2016-09-08 20:34 ` Peter.Chubb at data61.csiro.au
  0 siblings, 1 reply; 3+ messages in thread
From: Robert P. J. Day @ 2016-09-08 16:31 UTC (permalink / raw)
  To: u-boot


  from lib/hashtable.c:

  typedef struct _ENTRY {
        int used;
        ENTRY entry;
  } _ENTRY;

ok, that's just kind of creepy ... defining a typedef over top of a
struct of the same name. does anyone else find that strange?

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] "_ENTRY" is both a struct and a typedef?
  2016-09-08 16:31 [U-Boot] "_ENTRY" is both a struct and a typedef? Robert P. J. Day
@ 2016-09-08 20:34 ` Peter.Chubb at data61.csiro.au
  2016-09-09 11:15   ` Måns Rullgård
  0 siblings, 1 reply; 3+ messages in thread
From: Peter.Chubb at data61.csiro.au @ 2016-09-08 20:34 UTC (permalink / raw)
  To: u-boot

>>>>> "Robert" == Robert P J Day <rpjday@crashcourse.ca> writes:

Robert>   from lib/hashtable.c:

Robert>   typedef struct _ENTRY { int used; ENTRY entry; } _ENTRY;

Robert> ok, that's just kind of creepy ... defining a typedef over top
Robert> of a struct of the same name. does anyone else find that
Robert> strange?

It's standard practice in some C styles.  Personally I'd delete the
struct tag, as the typedef should be used everywhere instead.

Peter C
-- 
Dr Peter Chubb         Tel: +61 2 9490 5852      http://ts.data61.csiro.au/
Trustworthy Systems Group                           Data61 (formerly NICTA)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] "_ENTRY" is both a struct and a typedef?
  2016-09-08 20:34 ` Peter.Chubb at data61.csiro.au
@ 2016-09-09 11:15   ` Måns Rullgård
  0 siblings, 0 replies; 3+ messages in thread
From: Måns Rullgård @ 2016-09-09 11:15 UTC (permalink / raw)
  To: u-boot

<Peter.Chubb@data61.csiro.au> writes:

>>>>>> "Robert" == Robert P J Day <rpjday@crashcourse.ca> writes:
>
> Robert>   from lib/hashtable.c:
>
> Robert>   typedef struct _ENTRY { int used; ENTRY entry; } _ENTRY;
>
> Robert> ok, that's just kind of creepy ... defining a typedef over top
> Robert> of a struct of the same name. does anyone else find that
> Robert> strange?
>
> It's standard practice in some C styles.  Personally I'd delete the
> struct tag, as the typedef should be used everywhere instead.

I'd rather drop the typedef.  The struct/typedef is only referenced by
name in two places.

First in include/search.h:

/* Opaque type for internal use.  */
struct _ENTRY;
[...]
/* Data type for reentrant functions.  */
struct hsearch_data {
	struct _ENTRY *table;

It is standard practice to use "struct foo" in such constructs.

The second use is further down in lib/hashtable.c:

	htab->table = (_ENTRY *) calloc(htab->size + 1, sizeof(_ENTRY));

This line is terrible for two reasons:
1. Type-casting the return value of calloc is always wrong.
2. It is safer to use sizeof(*htab->table) instead of an explicit type.

If someone *really* wants to "fix" this, the proper thing is to drop the
typedef and rewrite the calloc line to not explicitly mention the type.

Then again, this is code borrowed from uclibc/glibc, so perhaps it's
best to simply leave it alone.

-- 
M?ns Rullg?rd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-09 11:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-08 16:31 [U-Boot] "_ENTRY" is both a struct and a typedef? Robert P. J. Day
2016-09-08 20:34 ` Peter.Chubb at data61.csiro.au
2016-09-09 11:15   ` Måns Rullgård

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.