Thanks, Jiri for the detailed explanation. It really answered my query very
well. I will continue with the PR, thanks for the comments there.

On Sun, Apr 11, 2021 at 11:47 PM Jiri Daněk <[email protected]> wrote:

> On Sun, Apr 11, 2021 at 7:33 PM Rakhi Kumari <[email protected]> wrote:
>
>> Hi,
>>
>> I'm working on PROTON-2370
>> <https://issues.apache.org/jira/browse/PROTON-2370> and created the
>> draft PR <https://github.com/apache/qpid-proton/pull/309> for the same.
>> While working on it I was seeing code snippets similar to "struct
>> pn_session_t;", I haven't seen this C++ syntax before. Can you please tell
>> me what it means?
>>
>
> Hey, I am not sure what exactly you are asking, so I am going to give a
> long-winded answer, sorry. A struct is a carry-over from the C language. So
> the answer depends on whether you are compiling your code as C or C++.
>
> In C++ a struct it is like a class where the default access modifier is
> public:, unless you declare it otherwise. In a C++ class, all members are
> private: by default, unless you declare otherwise.
>
> When you compile as C, a struct can only have data members, no methods.
> That's because C is not an object-oriented language, so the C++ syntax to
> add methods is not supported. If you want to have objects in C, you can
> define functions that take the struct (or pointer to a struct, more like)
> as their first argument (for consistency), name the functions in a
> consistent way, and only manipulate the struct using these functions; which
> is exactly what Proton-c does. You cannot have inheritance in C, though.
> Well, actually, you can use a library to add some object support to C, for
> example https://en.wikibooks.org/wiki/C_Programming/GObject, but Proton-c
> does not use any of that.
>
>
>>
>> https://github.com/apache/qpid-proton/blob/df978869030bb811b5e9cd99f6c390c9ca9bf97c/cpp/src/proton_bits.hpp#L42
>>
>
> That on line 42 is a forward declaration of a struct. You can do this
> instead of actually including the header file, and then you can use the
> type as a reference (pointer). You cannot use it as a value because with
> only a forward-declaration, the compiler does not know the size of the
> struct. Usually it is better to simply include the header; you may not want
> to do that 1) for compile efficiency, if the header file is very big 2) if
> the header file is not available, as e.g. in this case in Proton, the
> header is called "engine-internal.h"; private headers are one way in C to
> achieve encapsulation; here the C++ binding is breaking encapsulation, to
> some (small) degree, hopefully for good reasons.
>
>
>> I'm trying to understand the above in order to fix the build error I'm
>> getting on the same PR. In case you already know what's wrong here, can you
>> please guide me?
>>
>>
>> https://github.com/apache/qpid-proton/blob/df978869030bb811b5e9cd99f6c390c9ca9bf97c/cpp/include/proton/tag.hpp#L42
>>
>>
>> [image: image.png]
>>
>
> Please don't include pictures in e-mails to the mailing list; the mailing
> list is afaik striping them, the only reason I see this is that you sent me
> a CC in addition 'P Simply copy-paste the text from the terminal. The text
> color does not matter.
>
> I'm going to comment on the PR directly, just because I can 'P BTW, thanks
> for posting the PR, it helps with debugging. I can simply pull your code in
> its entirety and play with it...
> --
> Mit freundlichen Grüßen / Kind regards
> Jiri Daněk
>

Reply via email to