-
The stack example on https://github.com/c3lang/c3c includes code to realloc the stack when size catches up with capacity, but I don't see how the initial allocation (and initialization of the size and capacity variables) takes place. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
C3 uses zero initialization by default, so we'll always get it with zero size and capacity. Realloc can safely be used for the first allocation because if you pass |
Beta Was this translation helpful? Give feedback.
-
I found the discussion of initialization quickly when I went to https://c3-lang.org/getting-started/ and looked under Language Fundamentals / Variables, so that is good. I meant to suggest that you add a comment such as:
to the stack example on https://github.com/c3lang/c3c, since that is the very first exposure some people (like me) will have to the language. Another topic: I'm an old fogey (first programming job in 1967), and I'm used to there being a language reference manual in addition to other types of documentation such as tutorials, quick-start guides, etc. I find your documentation tends to have all the facts, but not always where I'd expect to find them. For example, Language Fundamentals / Statements mentions if statements from time to time, but the first example doesn't have an else clause. It sounds like I should interpret the sentence "Statements largely work like in C, but with some additions." as meaning: it's just like C unless we say something different somewhere in these web pages." The nice thing about a reference manual is that it puts a bound on where someone needs to look to get an answer to a question about a language, and it will often have an index to make that even easier. |
Beta Was this translation helpful? Give feedback.
C3 uses zero initialization by default, so we'll always get it with zero size and capacity. Realloc can safely be used for the first allocation because if you pass
null
to realloc it essentially works as malloc.