169 похожих чатов

Every now and then I remember that C has function

pointers and I just wonder why. It’s like the least ergonomic language feature I think I’ve ever seen, and never once have I seen them used without it feeling like a super alien kludge. I’d use flag bit packing bullshit too if function pointers were the option I had for injecting one function into another.

And like they’re this obnoxious to use and yet they have to be a designed feature right? It’s not obvious that you should be able to address a function, and there’s specific syntax for it, so someone must have sat down at some point and said “yes, this is how function pointers should work”

10 ответов

6 просмотров

Why is it unergonomic? And why is it unobvious that functions should be addressable

callbacks ig?

Thomas
Why is it unergonomic? And why is it unobvious th...

i understand the hate for asterisks, assembly uses square brackets for pointers and honestly its way easier to comprehend visually at first

Thomas
Why is it unergonomic? And why is it unobvious th...

im not a c dev but i think that's the only way to use callbacks, right?

demon with L
im not a c dev but i think that's the only way to ...

Well a callback must be passed as an argument

Lanny- Автор вопроса
Thomas
Why is it unergonomic? And why is it unobvious th...

The syntax is p funky imo, I mean you need something but why the extra parens? Why the asterisk on the identifier and not after the arg list? That’s mostly a taste thing but it does feel kludgy compared most the rest of the language and it’s something I always have to look up. More substantially, you can’t dereference a function pointer and expect anything meaningful to result, so the most fundamental operation of a pointer is basically unused. Pointer arithmetic doesn’t really work either, since depending on architecture a function pointer is not necessarily in the same address space as data. So I guess my complaint is that a function pointer is basically not a pointer, imo defining an opaque func_t or something and an apply function or built in would have been preferable

Lanny
The syntax is p funky imo, I mean you need somethi...

You'd love learning about execution tokens in Forth

Lanny
The syntax is p funky imo, I mean you need somethi...

Syntax stuff I was expecting, but the pointer operation stuff makes sense too

Lanny
The syntax is p funky imo, I mean you need somethi...

I guess you could have a separate "function address" type entirely

Похожие вопросы

Обсуждают сегодня

30500 за редактор? )
Владимир
47
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
Ребят в СИ можно реализовать ООП?
Николай
33
https://github.com/erlang/otp/blob/OTP-27.1/lib/kernel/src/logger_h_common.erl#L174 https://github.com/erlang/otp/blob/OTP-27.1/lib/kernel/src/logger_olp.erl#L76 15 лет назад...
Maksim Lapshin
20
Он в одиночку это дело запилил или была какая-то команда?
Aquinary
12
~ 2m21s  nix shell github:nixos/nixpkgs#stack ~  stack ghc -- --version error: … while calling the 'derivationStrict' builtin at /builtin/derivation.nix:...
Rebuild your mind.
6
Oh sorry did you want it in Gunter's chains?
Martin Rys
15
Всем привет, нужна как никогда, нужна помощь с IO в загрузчике. Пишу в code16 после установки сегментных регистров, пишу вывод символа. Пробовал 2 варианта: # 1 mov $0x0E, %a...
Shadow Akira
14
Подскажите пожалуйста, как в CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); получить наз...
A Z
7
Всем привет! Имеется функция: function IsValidChar(ch: UTF8Char): Boolean; var i: Integer; ValidChars: AnsiString; begin ValidChars := 'abcdefghijklmnopqrstuvwxyzABCDE...
Евгений
44
Карта сайта