Skip to content

How are interfaces and methods implemented? #1910

Answered by funny-falcon
funny-falcon asked this question in Q&A
Discussion options

You must be logged in to vote

I'll try to answer myself.
I use godbolt for that (c3's version is 0.6.2):

  • there're type description/reflection structures
  • third field of type description is a start of single-linked list
  • every dynamic method is just added to this linked list as struct method { void *funcptr; const char *selector; struct method *next} (excuse me for using C syntax).
  • selector is compared as a pointer (to constant string), not as a string itself. (btw, how it will work on Windows? Or LLVM on Windows does immutable string literals as well?)
  • interface is a struct with two pointers: to type's reflection structure and to value.

So, there is not "method tables" in terms of C++ virtual functions or Go's interfa…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@funny-falcon
Comment options

@lerno
Comment options

@funny-falcon
Comment options

Answer selected by funny-falcon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants