Connecting Tech Pros Worldwide Forums | Help | Site Map

struct stat st; stat(fileName.c_str(), &st); hu?

Steven T. Hatton
Guest
 
Posts: n/a
#1: Jul 23 '05
I found the following two statements in the file linked below:

struct stat st;
stat(fileName.c_str(), &st);

http://websvn.kde.org/branches/work/...47&view=markup

This is from /usr/include/sys/stat.h which I'm pretty sure is what #include
<sys/stat.h> is pulling in. I plain and simply do not understand what the
above two lines of code do. Can someone please explain?

extern int stat (__const char *__restrict __file,
struct stat *__restrict __buf) __THROW;

--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell

Pete Becker
Guest
 
Posts: n/a
#2: Jul 23 '05

re: struct stat st; stat(fileName.c_str(), &st); hu?


Steven T. Hatton wrote:[color=blue]
> I found the following two statements in the file linked below:
>
> struct stat st;
> stat(fileName.c_str(), &st);
>
> http://websvn.kde.org/branches/work/...47&view=markup
>
> This is from /usr/include/sys/stat.h which I'm pretty sure is what #include
> <sys/stat.h> is pulling in. I plain and simply do not understand what the
> above two lines of code do. Can someone please explain?
>
> extern int stat (__const char *__restrict __file,
> struct stat *__restrict __buf) __THROW;
>[/color]

Pretend it says this:

struct stat
{
// whatever...
};

extern int STAT(const char *, struct stat *);

struct stat st; // defines object of type struct stat
STAT(fileName.c_str(), &st); // call STAT

This is a quirk in the standard C library: there's a struct named 'stat'
and a function named 'stat'. When you say "struct stat" you're talking
about the struct; when you say "stat" you're talking about the function.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jack Klein
Guest
 
Posts: n/a
#3: Jul 23 '05

re: struct stat st; stat(fileName.c_str(), &st); hu?


On Wed, 01 Jun 2005 11:44:44 -0400, Pete Becker <petebecker@acm.org>
wrote in comp.lang.c++:
[color=blue]
> Pretend it says this:
>
> struct stat
> {
> // whatever...
> };
>
> extern int STAT(const char *, struct stat *);
>
> struct stat st; // defines object of type struct stat
> STAT(fileName.c_str(), &st); // call STAT
>
> This is a quirk in the standard C library: there's a struct named 'stat'
> and a function named 'stat'. When you say "struct stat" you're talking
> about the struct; when you say "stat" you're talking about the function.[/color]

If it was anyone who didn't work for Dinkumware, I'd have to point
that the problem is not with the "standard C" library.

Oh, what the heck, I just did that anyway.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Pete Becker
Guest
 
Posts: n/a
#4: Jul 23 '05

re: struct stat st; stat(fileName.c_str(), &st); hu?


Jack Klein wrote:[color=blue]
> On Wed, 01 Jun 2005 11:44:44 -0400, Pete Becker <petebecker@acm.org>
> wrote in comp.lang.c++:
>
>[color=green]
>>Pretend it says this:
>>
>>struct stat
>>{
>>// whatever...
>>};
>>
>>extern int STAT(const char *, struct stat *);
>>
>>struct stat st; // defines object of type struct stat
>>STAT(fileName.c_str(), &st); // call STAT
>>
>>This is a quirk in the standard C library: there's a struct named 'stat'
>>and a function named 'stat'. When you say "struct stat" you're talking
>>about the struct; when you say "stat" you're talking about the function.[/color]
>
>
> If it was anyone who didn't work for Dinkumware, I'd have to point
> that the problem is not with the "standard C" library.
>
> Oh, what the heck, I just did that anyway.
>[/color]

Good point. It's not the standard C library; it's the usual C library,
i.e., a UNIXism incorporated into POSIX and into most C libraries. I
don't know of any other code that does this, and it required a change to
the original grammar in C++ to make it work.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Closed Thread