4

Possible Duplicate:
what is a “private header” in c

I refer to this question:

Can you write object-oriented code in C?

The accepted answer to that question posted a link to a book: http://www.cs.rit.edu/~ats/books/ooc.pdf

In this book, the author uses *.r files, in addition to *.c and *.h files. The *.r files are used like-headers, hiding the implementation of "C-classes" from users

My question is what are *.r files?

are they something standard for coding in C?

Or is it something that Axel Schreiner came up with when writing his book?

Community
  • 1
  • 1
aCuria
  • 6,935
  • 14
  • 53
  • 89

2 Answers2

3

I had a quick look at the PDF, and here is an example of what you're referring to:

The type description struct Class in new.r should correspond to the method declarations in new.h:


struct Class {
  size_t size;
  void * (* ctor) (void * self, va_list * app);
  void * (* dtor) (void * self);
  void (* draw) (const void * self);
};

.r is referring to the representation (hence the .r) of the so-called class, where the header file actually defines the more friendly looking method names:

void * new (const void * class, ...);
void delete (void * item);
void draw (const void * self);

And finally the c source file contains the actual function code:

void draw (const void * self)
{ 
  const struct Class * const * cp = self;
  assert(self && * cp && (* cp) —> draw);
  (* cp) —> draw(self);
}

Long story short, yes the .r was something that Axel Schreiner came up with in his book, and as mentioned the r in .r is "representation".

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
onteria_
  • 68,181
  • 7
  • 71
  • 64
3

He calls them *r*epresentation files and hence the .r extension. It could might as well be .p or .q. Its just a personal convention used by the author.

freethinker
  • 1,286
  • 1
  • 10
  • 17