Reputation
527
Top tag
Next privilege 1,000 Rep.
See votes, expandable usercard
Badges
3 14
Impact
~7k people reached

Jul
20
comment Should I initialize C structs via parameter, or by return value?
@cmaster Ok, that's more clear. I can agree with that.
Jul
20
comment Should I initialize C structs via parameter, or by return value?
@cmaster Right. Ok. It's just, there's no actual constructors in C. In C++, it's impossible to get an instance of an object without "constructing" it. Constructors are called implicitly when getting an instance, and that's what I was trying to mimic here in C. But you might say that "C is not C++", in which case fine.
Jul
20
comment Should I initialize C structs via parameter, or by return value?
I didn't think copies would be an issue because of en.wikipedia.org/wiki/Copy_elision
Jul
20
comment Should I initialize C structs via parameter, or by return value?
@JacquesB I got " Every component that you build will be different than others. There is an Initialize() function used elsewhere for the struct. Technically speaking, calling it a constructor is misleading."
Jul
20
comment Should I initialize C structs via parameter, or by return value?
@Jefffrey We're in C, so we can't actually have methods. It's not always a direct set of values either. Sometimes initializing a struct is to get values(somehow), and performs some logic to initialize the struct.
Jul
20
comment Should I initialize C structs via parameter, or by return value?
Ok, seems reasonable. I was under the impression that initializing an object without being able to see what kind of input was initializing it, would lead to confusion. I was trying to follow the concept of data in / data out to produce predictable and testable code. Doing it the other way had seemed to increase coupling as the source file of my struct needed extra dependencies to perform the initialize. You're right though, in that I don't want to rock the boat unless one way is highly preferred over another.
Jul
20
comment Should I initialize C structs via parameter, or by return value?
@gnat This is an explicit question about struct initialization. That thread embodies some of the same rationale I would like to see applied for this particular design decision.
Jul
9
comment Does applying a prefix to member variables make sense in C?
@Ryan 90% with a C compiler, the rest with a C++ compiler, and all the C++ code has extern "C" so that it can be called from the C code. The codebase is by and large C with small additions of C++.
Jan
16
comment Is it a good idea to provide different function signatures that do the same thing?
lots of up-votes. I will stop immediately. thank you.
Sep
21
comment Why isn't the arrow operator in C++ just an alias of *.?
What does your example illustrate? Are you returning a smart pointer to a string and somehow outputting the size? I'm confused.