[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 1714050772306.png (28 KB, 767x689)
28 KB
28 KB PNG
Ok so, struct is a class, but shit.
>>
>>100174737
lol no?
>>
>>100174737
A struct is just a custom data type
>>
>>100174737
ye

they were around before the idea of scoped access was a thing, and in order to stay compatible with c code we still have them
>>
structs are useful, retard. It's just that cniles are retarded like you and don't understand that classes are useful too, just like you don't understand that structs are useful too.
>>
>>100174841
>scoped access
ironically, they had enough brain to make struct names be on a different semantic scope than variables names. You can use static global structs as sort of pseudoscopes too.
>>
>>100174870
i know what u mean but at the same time i dont lol
>>
why C is so gay it needs second time struct keyword
>>
>>100174878
yeah scoped access isn't the correct term but you know what i mean

object restricted access maybe
>>
>>100174737
In C, a struct is just a collection of data fields. It has no member functions and no inheritance, so it's hard to justify calling it a class.
(They also have their own namespace for legacy reasons, so you need to either use the struct keyword each time you refer to them or use a typedef.)

In C++, a struct is just a class whose members are public by default. If a struct or class contains only data fields and no constructors, virtual methods, etc then it's equivalent to a C struct and we call it a "POD type". The struct keyword quirk doesn't apply.
>>
>>100174737
If you're only going to use one variable in the struct then you should make it a union to save memory.
>>
>>100174963
thanks anon
and if you're not going to use negative numbers make sure to make it unsigned!
>>
>>100174896
>he thinks C has no inheritance
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>

struct wo
{
bool is_a_woman;
};

struct man
{
struct wo woman;
};

int main() {
struct man const male = {0};
struct wo const* const tranny = (struct wo const*)&male;
assert(tranny->is_a_woman);
}
>>
>>100174993
>
struct wo const* const tranny

god damn c is ugly
>>
structs are just classes with some limitations. unless you're using c++ in which case they're basically the same thing with minor differences
>>
>>100175016
lol the cope
>>
>>100174784
It's not his fault. OOP evangelists have poisoned everything and in the process completely forgot what defines OOP.
>>
>>100175036
>he thinks there's a strict definition for OOP
If there was any, good type system would be a minimum requirement, something C will never have.
>>
>>100174737
ehhh sort of, but not really
>>
>>100174896
Structs can have functions as members.
struct shit {
int (*func)(int ass);
};
>>
>>100175089
which has nothing to do with member functions that don't exist in C
>>
>>100174993
Yes, you can do it manually by exploiting the fact that casting a pointer to a struct into a pointer to its first member is guaranteed to be valid. And you can roll your own vtables if you want, like COM objects do.
That's different from formal language-level support for inheritance.

>>100175089
A member that is a function is not the same as a "member function" (method).
>>
>>100174784
Yes, why would you want to use a struct instead of a class? Is just a class but limited.
>>100174804
So class but worse.
>>100174870
>Structs are USEFUL
>How? I mean... They just ARE, OK!?
>>100174896
So it is a shit thing that no one would bother looking at, is confusing and you are better off using classes.
>>100175016
That's what I said. Classes, but shit.
>>
>>100175064
>>he thinks there's a strict definition for OOP
I made no such claim, because the definition has been shifting throughout time. However, nowadays people tend to think about everything in OOP terms because that's the only paradigm they are familiar with. And that is just stupid. At that point, there is no need to define OOP because it is void of meaning.

>good type system would be a minimum requirement
I disagree but that is beside the point.
>>
>>100174993
That's not an example of inheritance. You are casting a pointer to a different struct and that's what gives you then access to the field.
Also you embedded wo struct inside man struct. Are you implying that every man is a little girly inside?
>>
>>100175138
ok show me what OOP looks like without a good type system then
>>100175146
no idea, I don't get paid to model inheritance trees
>>
>>100175172
>what OOP looks like without a good type system
C++ comes to mind. Enjoy.
>>
>>100175192
My bad, I forgot that cniles are too mentally ill to understand anything that's not as shit as C, disregard anything I wrote or asked.
>>
>>100174737
structs are about data/storage, classes are about behavior
even though they are the same thing in c++ like other anons said



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.