Sizeof structure members

lvc at danews.UUCP lvc at danews.UUCP
Sun Jul 13 12:14:28 AEST 1986


I recently wrote a program that made use of the utmp structure.
I wanted to define a global character array of the same size as
a member (ut_line) of utmp.  Since the size is wired in as 12
and not #defined (which is what I would have done!), I decided to
define the array as:

char ftty[sizeof getutent()->ut_line];

I didn't want to define a global variable of type 'struct utmp *',
because I didn't need it, and lint would complain because I didn't
use it.  I could declare an external variable of type 'struct utmp *',
that I'd never use, but this seems just as bad as the unused global.

Without getutent() (which is what could happen in similar situations)
I believe I am stuck with either of the above 'solutions'.  Does anyone
know if I'm wrong about this ?  I use Sys 5 Rel 2 Unix.

Thanks,
-- 

Larry Cipriani		AT&T Network Systems
danews!lvc		"Nothing is worse than an itch you can never scratch."



More information about the Comp.lang.c mailing list