You don't need pointers - /g/ (#105591698) [Archived: 1154 hours ago]

Anonymous
6/14/2025, 4:27:55 PM No.105591698
1734730511622575
1734730511622575
md5: 9d44f26edfa86eeb789170083c1c5b1fšŸ”
Infinite growth is an infectious disease that turns everything into shit
Replies: >>105591723 >>105591732 >>105594284 >>105596023 >>105596058 >>105596140 >>105596217 >>105598872 >>105600169 >>105600527 >>105600993
Anonymous
6/14/2025, 4:31:13 PM No.105591723
>>105591698 (OP)
what if i want to add mods to model every molecule possible in your game mr anon
Replies: >>105591746
Anonymous
6/14/2025, 4:31:36 PM No.105591732
>>105591698 (OP)
Ok, what if you want to use more than 8 MiB of memory?
Replies: >>105591746
Anonymous
6/14/2025, 4:32:49 PM No.105591746
>>105591723
Refer to line 4.
>>105591732
Rewrite the program.
Anonymous
6/14/2025, 4:39:14 PM No.105591778
Rather generous filename length allowance
Replies: >>105593410 >>105600642
Anonymous
6/14/2025, 4:40:04 PM No.105591782
common on embedded systems. even though the hardware is good enough to not do it that way anymore, those parts of the code are usually quite old.
note that this will make it very easy to cheat engine your game.
Anonymous
6/14/2025, 7:55:25 PM No.105593410
>>105591778
what mainstream os even allows filenames over 255 bytes? iirc neither windows nor linux does
Replies: >>105601385
Anonymous
6/14/2025, 9:29:43 PM No.105594176
My game has 518400 entities. Is this ok op?
Anonymous
6/14/2025, 9:43:38 PM No.105594284
>>105591698 (OP)
Minecraft modders would like a word with you
Anonymous
6/15/2025, 1:08:03 AM No.105596023
>>105591698 (OP)
>Only 4096 files
Can't even compile Linux with this restriction.
Anonymous
6/15/2025, 1:12:51 AM No.105596058
>>105591698 (OP)
you're the reason why we can't have nice things
Anonymous
6/15/2025, 1:25:02 AM No.105596140
>>105591698 (OP)
You do need pointers.
Pointers are how addressing memory works, whether you are in control of them or not.
Replies: >>105598835
Anonymous
6/15/2025, 1:36:00 AM No.105596217
shrekcringe
shrekcringe
md5: 883cabb9b014cdf5e4fd703e89586389šŸ”
>>105591698 (OP)
>You don't need pointers
>OP pic literally has pointers
Anonymous
6/15/2025, 3:56:15 AM No.105597005
Array is just a syntactic sugar over pointer.
Replies: >>105598835 >>105600993
Anonymous
6/15/2025, 9:11:43 AM No.105598674
>you don't need pointers.
>declares 3.
Replies: >>105598835
Anonymous
6/15/2025, 9:39:47 AM No.105598835
>>105596140
>>105597005
>>105598674
why are cniles always so clueless about basic programming or even the c language they wank one over daily
Replies: >>105599005
Anonymous
6/15/2025, 9:45:56 AM No.105598872
>>105591698 (OP)
Great now write that in assembly without pointers
Replies: >>105599421
Anonymous
6/15/2025, 10:10:15 AM No.105599005
>>105598835
>why are cniles always so clueless about basic programming
Why are you so clueless about basic programming?
Anonymous
6/15/2025, 11:32:45 AM No.105599421
>>105598872
There are no pointers in assembly, retard
Replies: >>105599913
Anonymous
6/15/2025, 1:08:02 PM No.105599913
>>105599421
Are you actually retarded?
Any time you want to access something in memory, or put something in memory, you need that address somewhere. That's a pointer.
Replies: >>105599946 >>105601462
Anonymous
6/15/2025, 1:15:47 PM No.105599946
>>105599913
wrong, an address is an address
Replies: >>105599997
Anonymous
6/15/2025, 1:25:03 PM No.105599997
>>105599946
A pointer is an address.
Seriously, have you even done any assembly programming? Any at all?
Replies: >>105600014
Anonymous
6/15/2025, 1:27:53 PM No.105600014
>>105599997
wrong. In C, pointers are not addresses.
Replies: >>105600117 >>105601641
Anonymous
6/15/2025, 1:33:51 PM No.105600051
Write a linked list without pointer.
Anonymous
6/15/2025, 1:45:34 PM No.105600117
>>105600014
What do you think they are?
Replies: >>105600146 >>105600164 >>105600176
Anonymous
6/15/2025, 1:51:04 PM No.105600146
pointers
pointers
md5: 5c943b06193cd62a57ce385685558598šŸ”
>>105600117
(ntt)
abstract objects
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct s_str_a
{
size_t size;
char *text;
};

struct s_str_b
{
size_t size;
char text[];
};


int main(void)
{
char text[] = "this is a string";
struct s_str_a *str_a = malloc(sizeof(struct s_str_a));
struct s_str_b *str_b = malloc(sizeof(struct s_str_b) + sizeof(text));

str_a->text = text;
strcpy(str_b->text, text);

puts(str_a->text);
puts(str_b->text);


}

the practical difference is an additional level of dereferencing
Replies: >>105600214 >>105600376 >>105600696 >>105601445 >>105601469
Anonymous
6/15/2025, 1:53:43 PM No.105600164
>>105600117
A pointer is an address and the pointer's provenance.
Replies: >>105600227 >>105600707
Anonymous
6/15/2025, 1:54:39 PM No.105600169
>>105591698 (OP)
Why 512? vfat supports filenames up to 255 character encoded in UTF-16 (what Windows uses). If converted to UTF-8 (what Linux uses) it will take 765 bytes + 1 for null terminator.
Anonymous
6/15/2025, 1:57:46 PM No.105600176
>>105600117
heap memory
Anonymous
6/15/2025, 2:06:08 PM No.105600214
>>105600146
Both addresses, so what?
Replies: >>105600226 >>105600227
Anonymous
6/15/2025, 2:09:07 PM No.105600226
>>105600214
yeah but in one instance you get em with a dereferencing, in another with a simple add operation
both pointers.
but one is way faster than the other
pointers are abstract objects. they dont map 1:1 to underlying operations
theyre references.
Replies: >>105600267 >>105600351
Anonymous
6/15/2025, 2:09:11 PM No.105600227
>>105600214
wrong, see >>105600164
Anonymous
6/15/2025, 2:17:03 PM No.105600263
fixed length array schizo is at it again huh
Anonymous
6/15/2025, 2:17:43 PM No.105600267
>>105600226
>theyre references.
What do they reference?
Replies: >>105600276
Anonymous
6/15/2025, 2:19:09 PM No.105600276
>>105600267
the underlying data, duh
in the example: in one instance its an actual address
in the other: like a roadsign that says "here but
+ 8"
Anonymous
6/15/2025, 2:30:09 PM No.105600351
>>105600226
>but one is way faster than the other
They're the same speed.
The register to register mov and the add each take one cycle.
Replies: >>105600364
Anonymous
6/15/2025, 2:34:07 PM No.105600364
>>105600351
yeah but in one case you point to what could be yet another block of memory and in the latter youre pretty much guaranteed to find your data on the same page
i think the abstraction of a pointer is even more evident this way
more tangible
Anonymous
6/15/2025, 2:35:09 PM No.105600376
>>105600146
What if you need more than one flexible array in your struct?
Replies: >>105600397 >>105600404
Anonymous
6/15/2025, 2:38:53 PM No.105600397
>>105600376
thats a dumb question
you allocate a buffer and you subdivide it
how exactly you wanna do that is up to you its a matter of interfaces so you got plenty of options
Replies: >>105600404 >>105600415
Anonymous
6/15/2025, 2:40:25 PM No.105600404
>>105600376
>>105600397
(cont)
in other words
you reformulate your two flex arrays as one
Anonymous
6/15/2025, 2:41:56 PM No.105600415
>>105600397
>you allocate a buffer and you subdivide it
So you just create a pointer?
Replies: >>105600421
Anonymous
6/15/2025, 2:42:53 PM No.105600421
>>105600415
yeah
you think im op?
lamao no im not
op is bait you fkn dweeb
Anonymous
6/15/2025, 2:58:58 PM No.105600527
>>105591698 (OP)
I was going to say things like "Anon, how are you supposed to pass a buffer into a function without a pointer to its first element and its length? How are you going to implement interfaces without structures of function pointers? How are you going to have an 'out' parameter without pointers? How are you supposed to do any complex algorithms that require data structures with pointers in them?" Then I realized that languages less primitive than C allow you to do all of these things without explicit pointers (except maybe the part about the data structures that need pointers).
Replies: >>105600993
Anonymous
6/15/2025, 3:14:32 PM No.105600642
>>105591778
Runs out quite quickly the moment you start using japanese characters.
This is an actual issue i had with my anime sound tracks on Ext4
Anonymous
6/15/2025, 3:22:15 PM No.105600696
>>105600146
I'm sorry, but the more I consider what you're doing here, the more it seems pointers are just addresses.
You have two data structures, s_str_a and s_str_b somewhere in memory. str_a is the address of s_str_a and str_b is the address of s_str_b.
Only, s_str_a->text is a pointer, so it will be the address where text[] is somewhere in memory, while s_str_b->text is an array so you actually copy the contents text[] array into the area of the data structure.
What is the point? They're still just addresses. All you have done in one case is structured data in memory differently. One may be faster, but that's comes from the structuring the data so it is dereferenceable from the first pointer, the data is going to start 8 bytes after the address in the pointer.
Replies: >>105600707
Anonymous
6/15/2025, 3:24:29 PM No.105600707
>>105600696
wrong, see >>105600164
Replies: >>105600863
Anonymous
6/15/2025, 3:45:55 PM No.105600863
>>105600707
Provenance is something the compiler considers, it is not what the pointer is.
Replies: >>105600932
Anonymous
6/15/2025, 3:55:44 PM No.105600932
>>105600863
wrong
Replies: >>105600991
Anonymous
6/15/2025, 4:04:06 PM No.105600991
>>105600932
No, you.
Your code has no idea what the provenance is, the compiled code has no concept of provenance, it's not stored anywhere in the binary (for architectures like x86 at least).
It's something the compiler considers while doing optimizations.
Replies: >>105601009
Anonymous
6/15/2025, 4:04:08 PM No.105600993
>>105591698 (OP)
>pointers
>infinite growth
You have C brain damage. Pointers are a way to point to something in a memory space. They don't have "infinite growth."

>>105597005
>Array is just a syntactic sugar over pointer.
No they are not. Arrays have no pointers anywhere. An array is a data structure. On the hardware level, your arrays can be separate blocks of memory cells on the chip. Think about FPGAs.

>>105600527
>Anon, how are you supposed to pass a buffer into a function without a pointer to its first element and its length? How are you going to implement interfaces without structures of function pointers? How are you going to have an 'out' parameter without pointers? How are you supposed to do any complex algorithms that require data structures with pointers in them?
C cripples your mind. You don't need pointers for any of these things. You can pass an array "buffer" by value (in a vector or array register or over wires). You can implement interfaces with type-based case dispatching. You can have an out parameter in a register. FPGAs can do all these things without pointers.
Replies: >>105601105 >>105601405
Anonymous
6/15/2025, 4:05:54 PM No.105601009
>>105600991
low IQ retard
pointer = address + provenance
Replies: >>105601061 >>105601288
Anonymous
6/15/2025, 4:13:18 PM No.105601061
>>105601009
Wrong. A pointer is just an address.
What that address will be depends on the provenance, something the compiler works out (sometimes badly) during compilation.
Replies: >>105601117
Anonymous
6/15/2025, 4:20:47 PM No.105601105
>>105600993
>C cripples your mind. You don't need pointers for any of these things.
That's literally what I said in the second sentence.
Anonymous
6/15/2025, 4:22:11 PM No.105601117
>>105601061
wrong
>The provenance of a valid pointer is the ID of the specific storage instance to which the pointer refers (or one-past).
>This ID is a genuine component of the pointer value in C’s abstract machine, but does not necessarily take part
>in the object representation of the pointer; in general the provenance of a pointer is not observable.
Replies: >>105601245 >>105601288 >>105601667
Anonymous
6/15/2025, 4:40:10 PM No.105601245
>>105601117
>>This ID is a genuine component of the pointer value in C’s abstract machine
Yeah, essentially how it is going to be compiled.
Replies: >>105601291
Anonymous
6/15/2025, 4:47:49 PM No.105601288
>>105601009
>>105601117
>pointer = address + provenance
Provenance is more C brain damage. It doesn't really exist. Pointers can have more than an address, like type information or the size or bounds of what is being pointed to. Those actually exist as bits in the pointer.
Replies: >>105601328
Anonymous
6/15/2025, 4:48:14 PM No.105601291
>>105601245
dumb retard
Replies: >>105601357
Anonymous
6/15/2025, 4:55:18 PM No.105601328
>>105601288
retarded post
Replies: >>105601399
Anonymous
6/15/2025, 5:00:18 PM No.105601357
>>105601291
Have some light reading.
https://dl.acm.org/doi/pdf/10.1145/3290380
And play with the examples to understand what is going on.
Replies: >>105601375
Anonymous
6/15/2025, 5:02:10 PM No.105601375
>>105601357
So now you agree that pointer = address + provenance?
dumb retard
Replies: >>105601389 >>105601399
Anonymous
6/15/2025, 5:03:15 PM No.105601385
>>105593410
Linux allows paths up to 4k in a path with no single file name being greater than 255 bytes
Anonymous
6/15/2025, 5:03:43 PM No.105601389
>>105601375
No, because you haven't fucking read it yet.
Anonymous
6/15/2025, 5:05:08 PM No.105601399
>>105601328
>>105601375
"Provenance" is fake C bullshit that doesn't mean anything.
Replies: >>105601416
Anonymous
6/15/2025, 5:05:59 PM No.105601405
>>105600993
>Arrays have no pointers anywhere
An array is compiled to a pointer to a memory address it literally is a memory pointer that represents the abstract idea of a chain of bytes.

Every array in op code was compiled to a pointer to somewhere on the stack
Replies: >>105601425 >>105601659
Anonymous
6/15/2025, 5:07:26 PM No.105601416
>>105601399
https://rust-lang.github.io/rfcs/3559-rust-has-provenance.html
Replies: >>105601431
Anonymous
6/15/2025, 5:08:50 PM No.105601425
>>105601405
>An array is compiled to a pointer to a memory address it literally is a memory pointer that represents the abstract idea of a chain of bytes.
Arrays don't need pointers or memory addresses. C damaged your brain.
Replies: >>105601445 >>105601457 >>105601505
Anonymous
6/15/2025, 5:09:25 PM No.105601431
>>105601416
Who mentioned rust?
Replies: >>105601437
Anonymous
6/15/2025, 5:10:21 PM No.105601437
>>105601431
dumb retard
Anonymous
6/15/2025, 5:11:10 PM No.105601445
>>105601425
>Arrays don't need pointers or memory addresses.
Dear god...
You better not reference >>105600146 because that array has a pointer, the one holding the address of the struct it is in.
Replies: >>105601469
Anonymous
6/15/2025, 5:12:28 PM No.105601457
>>105601425
>Arrays don't need pointers or memory addresses. C damaged your brain.
They do.
Are you talking about placing 512 byte values in the avx-512 registers
Anonymous
6/15/2025, 5:12:57 PM No.105601462
>>105599913
This is what cnility does to a mf
Anonymous
6/15/2025, 5:13:58 PM No.105601469
>>105601445
>You better not reference >>105600146
The first structure has a pointer and no array The second structure has an array (in the brain damaged castrated C sense of "array") and no pointer.
Replies: >>105601481 >>105601489 >>105601492 >>105601549
Anonymous
6/15/2025, 5:15:31 PM No.105601481
>>105601469
Would you mind compiling any of this code you are currently imagining in your psychotic break and share the decompiled assembly with us so we can laugh at you?
Anonymous
6/15/2025, 5:16:54 PM No.105601489
>>105601469
>The second structure has an array (in the brain damaged castrated C sense of "array") and no pointer.
The pointer is the address of the struct
Replies: >>105601492 >>105601520
Anonymous
6/15/2025, 5:17:25 PM No.105601492
>>105601489
>The pointer is the address of the struct
Whoops pressed enter too soon
>>105601469
The pointer is the address of the struct plus the size of size_t
Replies: >>105601520
Anonymous
6/15/2025, 5:19:37 PM No.105601505
>>105601425
>Arrays don't need pointers or memory addresses. C damaged your brain.
They do if you ever want to read or write their contents.
Replies: >>105601532
Anonymous
6/15/2025, 5:20:58 PM No.105601520
>>105601489
>The pointer is the address of the struct
No, the struct and array are different things.

>>105601492
>The pointer is the address of the struct plus the size of size_t
So you don't know the difference between a struct and a pointer either. The size_t is PART OF the struct, not a pointer. If it wasn't there, the array still wouldn't be a pointer. The "array" is the "char text[]" in "s_str_b", not the whole "s_str_b" itself. "s_str_a" does not have an array, just a size_t and a pointer. C really damaged your brain. I know C better than you people and I don't even like C.
Anonymous
6/15/2025, 5:22:22 PM No.105601532
>>105601505
>They do if you ever want to read or write their contents.
That's C brain damage. Arrays are not something made up by C, they're a programming concept that was around for a long time before C. You do not need pointers to read or write contents of arrays.
Replies: >>105601545
Anonymous
6/15/2025, 5:23:46 PM No.105601545
>>105601532
>You do not need pointers to read or write contents of arrays.
Yet you cannot provide a single example.
Curious
Anonymous
6/15/2025, 5:24:13 PM No.105601549
>>105601469
The first structure has a pointer INSIDE IT and the second structure has an array INSIDE IT.
The address to the array in the second structure is just the address of the structure plus the offset of the size value at the beginning of the structure. str_b is essentially str_b->size.
So to reference that array, you need a pointer, which is the pointer to the struct, because you know where the array is in relation to the start of the struct in memory.
Replies: >>105601604
Anonymous
6/15/2025, 5:26:53 PM No.105601573
Sure. You can define a struct and there are no pointers anywhere. Even if you have a pointer in the struct, there are no pointers actually anywhere yet until you create the struct.
As soon as you create the struct, no matter what it contains, a pointer is created which points to the newly created struct. And regardless of the contents of that struct, each item within it is accessed using an offset of said pointer
Replies: >>105601607
Anonymous
6/15/2025, 5:31:00 PM No.105601604
>>105601549
>The first structure has a pointer INSIDE IT and the second structure has an array INSIDE IT.
Yes.
>The address to the array in the second structure is just the address of the structure plus the offset of the size value at the beginning of the structure. str_b is essentially str_b->size.
This is a limitation of C because of malloc returning a pointer to a byte. Programming languages do not have to do that.
>So to reference that array, you need a pointer, which is the pointer to the struct, because you know where the array is in relation to the start of the struct in memory.
This is another limitation of malloc. The struct itself does not have to be in memory or have an address.
Anonymous
6/15/2025, 5:32:14 PM No.105601607
>>105601573
No, structs don't need to be in memory or have an address.
Replies: >>105602282 >>105602292
Anonymous
6/15/2025, 5:37:39 PM No.105601641
>>105600014
This is bait.
Replies: >>105601667
Anonymous
6/15/2025, 5:40:39 PM No.105601659
>>105601405
>An array is compiled to a pointer to a memory address
In C. (Also, in C, pointers and arrays aren't the same thing). That's also why all arrays must be zero-indexed in C: there's no way to specify a custom range of indices, because all you have is a pointer to the first element of the array, and you can only specify it in terms of pointer offsets.
In languages that have slices, it will carry a pointer to its first element and something that indicates the length. Some languages have custom ranges of index (e.g. -7..7 rather than 0..14], in which case slices will have that as well. This extra information allows bounds checking and (like I said) custom ranges of indices.
Of course, the pointer will be there in assembly, but it's not exposed to the programmer.
Just like how you don't need to make the programmer write custom tables of function pointers to have inheritance, and you don't need to make the programmer use pointers to have out variables, you don't need to make the programmer use pointers to let them use arrays.
Anonymous
6/15/2025, 5:41:43 PM No.105601667
>>105601641
dumb retard, see >>105601117
Anonymous
6/15/2025, 6:56:45 PM No.105602282
>>105601607
You're correct. In the scenario you have described they are unused in the code and thus optimized by the compiler and excluded from the program
Anonymous
6/15/2025, 6:58:12 PM No.105602292
>>105601607
Where would a struct be stored if not in memory?
Replies: >>105602341
Anonymous
6/15/2025, 7:04:19 PM No.105602341
>>105602292
In the registers, or some kind of block RAM like an FPGA. It doesn't have to have a memory address.
Replies: >>105602360 >>105602446
Anonymous
6/15/2025, 7:05:46 PM No.105602360
>>105602341
oh i get it, youre retarded
Replies: >>105602719
Anonymous
6/15/2025, 7:15:06 PM No.105602446
>>105602341
>In the registers, or some kind of block RAM
Block RAM... You mean memory?

How do you propose register storage of a struct? Writing a compiler that takes structs and chunks them into 8 bytes and spreads them across registers?
That sounds useless and extremely limiting. What's the maximum size of a struct if we spread it across all register? Like maybe 128 bytes of on chip storage and then you run out of free registers to operate on the struct with,?
Literally retarded
Replies: >>105602719 >>105602722
Anonymous
6/15/2025, 7:48:00 PM No.105602719
>>105602360
>oh i get it, youre retarded
>>105602446
>How do you propose register storage of a struct?
You know, for the System V ABI, struct fields will be passed in registers as if they were individual parameters. Here's an example showing proof if you don't believe me; just read the assembly.
https://godbolt.org/z/xxb94zfKx
Furthermore, it's a common optimization to hold struct fields in registers as opposed to on the stack as long as the values of those registers are stored back into the struct before it's used (like if its address is exposed or it's returned from a function).
It's really not that amazing to store structures in registers at least part of the time.
Anonymous
6/15/2025, 7:48:08 PM No.105602722
>>105602446
>Block RAM... You mean memory?
It's not part of a linearly addressed memory like C mandates. You can't have a pointer to it from somewhere else. Each block RAM can be used for an array but the array doesn't have an address. There's no concept of what's "before" or "after" the RAM like there is in C. In C, you have an array or struct that has bytes "before" it and "after" it and you can do pointer arithmetic to get to those bytes.
>How do you propose register storage of a struct? Writing a compiler that takes structs and chunks them into 8 bytes and spreads them across registers?
In most programming languages, it doesn't have to be in one big linearly addressed memory or accessible from somewhere else. Your struct of 1 int and 3 floats might be stored in 3 FPU registers and one integer register. Ada and Pascal for example allow this.