|
leper khan posted:Lol at saying C doesn't have anonymous functions. hobbesmaster posted:C lets you do whatever you want, it owns C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all
|
# ? Jun 13, 2022 18:31 |
|
|
# ? Jun 7, 2024 21:03 |
|
DELETE CASCADE posted:C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all Works fine in K&R on all platforms that were contemporary to K&R
|
# ? Jun 13, 2022 18:35 |
|
DELETE CASCADE posted:C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all get a load of this nerd
|
# ? Jun 13, 2022 18:40 |
|
Sudden flashback to a Star Wars webcomic where R2D2 says that everything not forbidden is allowed and C3P0 says something like "What is this Microsoft bullshit?"
|
# ? Jun 13, 2022 18:41 |
|
"undefined behavior" includes possibly being able to do it with consistent results, as I have done in the write routine of a flash memory driver that needed to copy itself out of flash into ram and then jump to itself for the actual writing
|
# ? Jun 13, 2022 18:41 |
|
how else am I gonna run an arbitrary payload in your stupid as hoc parser
|
# ? Jun 13, 2022 18:42 |
|
leper khan posted:Works fine in K&R on all platforms that were contemporary to K&R there is nothing anywhere in K&R that casts a data pointer to a function pointer or even suggests that this might be possible
|
# ? Jun 13, 2022 18:48 |
|
gonadic io posted:Ask me how I know that inline(always) does not mean always You were smart and read the docs before using it?
|
# ? Jun 13, 2022 18:48 |
|
Xarn posted:You were smart and read the docs before using it? hey it's not inline(mostly)
|
# ? Jun 13, 2022 18:50 |
|
https://gist.github.com/tp7/e12143e48503f19398f0code:
|
# ? Jun 13, 2022 19:10 |
|
obviously non-portable. i specified ansi C in my original wordspost for a reason
|
# ? Jun 13, 2022 19:47 |
|
yes yes i know posix does it for dlsym(). it's still considered an unportable extension. but the questionable ability to turn an arbitrary block of data into a function doesn't somehow give you the power to program in a closure-based style in C, we still haven't solved any of the memory management issues
|
# ? Jun 13, 2022 19:55 |
|
CPColin posted:I've been through the lambda on a func with no name
|
# ? Jun 13, 2022 20:33 |
|
DELETE CASCADE posted:C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all tell me you're a C standard committee member without telling me you're a C standard committee member
|
# ? Jun 13, 2022 20:36 |
|
if it runs (and passes all the tests) then ship it
|
# ? Jun 13, 2022 20:43 |
|
You can write anything you want in a commit as long as you understand that someone will eventually hack a dev's computer, pull the repo, and publish it for the world to see. Or someone will hack into a webserver via yet another zero day flaw in wordpress, and pull all the git repos.
|
# ? Jun 13, 2022 20:44 |
|
Who needs automatic memory management, when you can just yolo things with manual memory management in C++ lambdas.
|
# ? Jun 13, 2022 21:28 |
|
c has had closures for years in macOS/iOS
|
# ? Jun 13, 2022 22:36 |
|
DELETE CASCADE posted:C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all pathetic, cowardly behavior by the c standardization committee. it's my memory, i should be able to interpret it however i want
|
# ? Jun 14, 2022 00:51 |
|
DELETE CASCADE posted:C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all So what you're saying is that C totally lets you do it, it just doesn't promise that it will work.
|
# ? Jun 14, 2022 00:56 |
|
gonadic io posted:Typically in those cases it's whatever your untrusted executable has smuggled in as a payload and has swapped with the stack pointer wants
|
# ? Jun 14, 2022 01:03 |
|
DELETE CASCADE posted:C absolutely does not let you do this. malloc returns a data pointer. casting a data pointer to a function pointer (so that you can call your block of machine code) is undefined behavior. the C standard is very clear about this, there is no room for interpretation. if you do it anyway and it happens to work, you are just lucky. it could stop working on any platform at any time for any reason or no reason at all true, you should use mmap with PROT_EXEC (or whatever the windows VirutalAlloc equivalent is). dosbox had a bug due to this at some point
|
# ? Jun 14, 2022 01:11 |
|
Presto posted:So what you're saying is that C totally lets you do it, it just doesn't promise that it will work. Undefined behavior is just ambiguous and unspecified. Nothing wrong with it or using it, your code may just be slightly less portable. This is one of the reasons I still have compilers from the 80s and early 90s sitting around. Portability generally isn't the primary concern. Running on target hardware is.
|
# ? Jun 14, 2022 01:12 |
|
leper khan posted:Undefined behavior is just ambiguous and unspecified. Nothing wrong with it or using it, your code may just be slightly less portable. No, that's "unspecified behaviour". "Undefined behaviour" is different. The big problem is that if part of your code exhibits undefined behaviour, then the compiler is under no obligation to ensure that the rest of your code actually does what it says it does.
|
# ? Jun 14, 2022 03:07 |
|
isn't it assumed that approximately zero useful c codebases are devoid of undefined behaviour?
|
# ? Jun 14, 2022 04:26 |
|
Doom Mathematic posted:The function with no name is actually credited as "Joe". malloc smithee
|
# ? Jun 14, 2022 04:59 |
|
pokeyman posted:isn't it assumed that approximately zero useful c codebases are devoid of undefined behaviour? I think most large codebases will have pieces of them that exhibit undefined behaviour on certain inputs, but not always inputs that happen in practice. But that's okay! (In fact, that's kind of the point of having that behaviour be undefined - the compiler is allowed to assume that it never happens instead of having to prove that it never happens). It's only a problem if the thing that the compiler assumes never happens, actually happens.
|
# ? Jun 14, 2022 05:23 |
|
yeah, there's very big gaps between "this function would hit ub given certain inputs but it's never called with those", "this function hits ub in rare scenarios but the happy-path is well defined", and "this function's happy path is ub". the first is perfectly fine. the second is the source of "impossible" bugs that you can never figure out how to repro and close the bug report with "let's pretend this went away" after a few years. basically all c programs have some of these. the third means that you aren't writing c; you're writing in an ad-hoc c-like language that one specific compiler presumably compiles as desired.
|
# ? Jun 14, 2022 05:39 |
|
This is a good video about why it could be worse if certain cases of undefined behaviour were changed to implementation defined behaviour. https://m.youtube.com/watch?v=yG1OZ69H_-o
|
# ? Jun 14, 2022 05:56 |
|
I was relieved recently when I realized that I didn't care about a certain, probably impossible combination of inputs to a function, because it meant I could drop in a "this combination is undefined" comment and move on with my day.
|
# ? Jun 14, 2022 06:36 |
|
other undefined operations in c include: An unmatched ' or " character is encountered on a logical source line during tokenization (6.4).
|
# ? Jun 14, 2022 11:19 |
|
Gentle Autist posted:
|
# ? Jun 14, 2022 11:19 |
|
one thing I heartily enjoy with vscode is how I can alt tab switch around poo poo and come back to it half way waiting for me to finish typing what I was doing gently caress this bullshit that I was dealing with affinity photo the other night and I was trying to copy a rgb value without hex and so I was trying to alt tab between the apps remembering one number at a time, but fuckin affinity as soon as you lose focus it drops the rgb picker and so you cannot do what I want it to do. vschode does it and I love it for it
|
# ? Jun 14, 2022 11:45 |
|
echinopsis posted:one thing I heartily enjoy with vscode is how I can alt tab switch around poo poo and come back to it half way waiting for me to finish typing what I was doing idk i just tried typing half of a command into the f1 palette and it went away when i alt-tabbed
|
# ? Jun 14, 2022 11:55 |
|
all i know about lambders is my freshman year data structures old dilf professor begrudgingly taught their implementation in java because "i guess that's just what's hip nowadays, i don't get it though" a function without a name ..... so sad .... ):
|
# ? Jun 14, 2022 19:49 |
|
people used to object-oriented languages don't generally see the need for closures, because you can do all the same stuff with classes and object constructors. it tends to be quite more verbose though, in my opinion. also involves more non-local mutability which is harder to reason about
|
# ? Jun 14, 2022 19:55 |
|
DELETE CASCADE posted:people used to object-oriented languages don't generally see the need for closures, because you can do all the same stuff with classes and object constructors. it tends to be quite more verbose though, in my opinion. also involves more non-local mutability which is harder to reason about
|
# ? Jun 14, 2022 19:57 |
|
DELETE CASCADE posted:people used to object-oriented languages don't generally see the need for closures, because you can do all the same stuff with classes and object constructors. it tends to be quite more verbose though, in my opinion. also involves more non-local mutability which is harder to reason about yeah that was pretty much his stance. just told us to use them in place of writing all the boilerplate to implement an anonymous functional interface he's also been teaching the intro java stuff for like, 15 years, so yeah he has objects brain. they teach you language paradigms n stuff completely later
|
# ? Jun 14, 2022 20:08 |
|
just occurred to me that it is possible some yosposters a generation above me had this professor in their undergrad and that's both cool and scary. i remember a few of y'all went to my university edit: remember as in i saw it lurking a while ago
|
# ? Jun 14, 2022 20:16 |
|
|
# ? Jun 7, 2024 21:03 |
|
mystes posted:You think using closures for private members like in JavaScript is easier to reason about? if it means nobody can mutate those private members out from under me, then yes. unfortunately in javascript it does not mean that
|
# ? Jun 14, 2022 21:19 |