eschaton posted:it's entirely legal to call main() recursively So I've been searching around some more and I'm becoming increasingly convinced that in C, recursive calls to main() are actually legal. I'm curious what the various compiler writers in this thread have to say about it though (I forget if you are one of them, so apologies if you are--I just remember you as one of the people who probably knows much more C/C++ than me).
|
|
# ? Nov 23, 2016 05:45 |
|
|
# ? May 24, 2024 16:38 |
|
shamefully quoting myself from ages ago butquote:comment threads about dumb programming poo poo always be like
|
# ? Nov 23, 2016 06:03 |
|
Sapozhnik posted:shamefully quoting myself from ages ago but why do u h8 fun mate?
|
# ? Nov 23, 2016 06:08 |
LeftistMuslimObama posted:why do u h8 fun mate? Agreed with LMO; I enjoy seeing interesting / unusual solutions to a well-known problem.
|
|
# ? Nov 23, 2016 06:16 |
|
code:
quote:Or the ultimate optimized version with hardcoded output, no standard library or main function, and direct assembly syscalls to write to stdout. From https://www.rosettacode.org/wiki/FizzBuzz#Rust
|
# ? Nov 23, 2016 06:33 |
See this is why Rust needs constexpr / turing-complete generics / whatever. You should be able to make the compiler generate that hardcoded output for you! (very cool solution btw)
|
|
# ? Nov 23, 2016 06:40 |
|
Sapozhnik posted:shamefully quoting myself from ages ago but man ur a fun guy
|
# ? Nov 23, 2016 06:42 |
|
because the point of fizzbuzz is to prove that you aren't a complete charlatan and absolutely nothing beyond that. passing fizzbuzz with flying colors means you get to continue the phone screen beyond the first 5 minutes, it doesn't get you the job. if u really feel the need to strenuously prove in a multitude of elaborate ways that you are not in fact a complete charlatan then idk what to tell u
|
# ? Nov 23, 2016 07:03 |
|
VikingofRock posted:So I've been searching around some more and I'm becoming increasingly convinced that in C, recursive calls to main() are actually legal. I'm curious what the various compiler writers in this thread have to say about it though (I forget if you are one of them, so apologies if you are--I just remember you as one of the people who probably knows much more C/C++ than me). it's not really a debatable topic; the spec says something or it doesn't. C++ does not allow it. C++14 Standard posted:The function main shall not be used within a program. The linkage (3.5) of main is implementation-defined. A program that defines main as deleted or that declares main to be inline, static, or constexpr is ill- formed. The name main is not otherwise reserved.
|
# ? Nov 23, 2016 07:10 |
|
ugh fine here's one partial Verilog implementationcode:
|
# ? Nov 23, 2016 08:03 |
leper khan posted:it's not really a debatable topic; the spec says something or it doesn't. C++ does not allow it. Yeah but that's the C++ standards. As far as I can tell the C standards all allow it.
|
|
# ? Nov 23, 2016 08:12 |
|
leper khan posted:it's not really a debatable topic; the spec says something or it doesn't. C++ does not allow it. i'm not sure what 'shall not be used' means in the context of the c++ spec, but implementation-defined is not undefined so it might be cool sometimes?
|
# ? Nov 23, 2016 08:29 |
redleader posted:i'm not sure what 'shall not be used' means in the context of the c++ spec, but implementation-defined is not undefined so it might be cool sometimes? Nah I'm pretty sure that violating a "shall" means that your program is ill-formed, and thus doing so is UB. So I think it's pretty clear that you can not call main() recursively in C++.
|
|
# ? Nov 23, 2016 08:48 |
|
make another recursive function, have main call it, whooooo caaaares wtbfd
|
# ? Nov 23, 2016 08:59 |
|
whoops i just wasted minutes of my life on this planet trying to find what the c++ spec means by "ill-formed" for some reason
|
# ? Nov 23, 2016 09:14 |
|
Soricidus posted:is rust good at small programs? I thought it was a big complex language for big complex systems like browsers it's very good. cargo and crates.io are good and cool. i made some network protocol (!) parsers using nom and it was easy peasy (the whole code could fit in a single paper). also multithreaded code is very easy in rust. check rayon if you want some quick parallelism wins. ps: use rustup to install rust. it's the quickest way to dl and update the toolkit. it works perfectly on windows Workaday Wizard fucked around with this message at 10:23 on Nov 23, 2016 |
# ? Nov 23, 2016 09:56 |
|
VikingofRock posted:Nah I'm pretty sure that violating a "shall" means that your program is ill-formed, and thus doing so is UB. So I think it's pretty clear that you can not call main() recursively in C++. just make your program a quine that compiles and executes itself with new arguments to implement recursion
|
# ? Nov 23, 2016 10:22 |
|
Bognar posted:2. using a weird .Any call instead of a foreach loop (or the .ForEach method) I'm not totally convinced though so I still do it in Swift
|
# ? Nov 23, 2016 11:35 |
|
I see your TMP fizzbuzz and raise you TMP Turing Machine. http://coliru.stacked-crooked.com/a/de06f2f63f905b7e
|
# ? Nov 23, 2016 11:48 |
|
Plorkyeran posted:this would be under 50 lines of code with libclang and is a nice excuse to learn how to use it Ok, I needed a reason to learn it anyway.
|
# ? Nov 23, 2016 11:49 |
|
toiletbrush posted:I used to write an extension method on IEnumerable to add an '.each(...)' method but whenever I did I had a spidey sense tingle that it was a bad thing to do - partially because if it didn't already exist it was probably for a good reason, and also because the fact it didn't return anything meant it had to be causing side effects (not that calling that out is a bad thing). Then a developer joined the team who was much better than me and said 'dont do that' and sort of confirmed my spidey sense. c# hero eric lippert has written about why there isn't an IEnumerable.ForEach() method in the standard library - as you say, it basically boils down to "side effects"
|
# ? Nov 23, 2016 12:12 |
|
I'm kind of pissed off at celery. they keep changing the default way to do stuff (like scheduling tasks), broke a lot of poo poo in version 4.0 and there's zero response from the developers. what I'm saying is: don't choose celery for your project, maybe consider using erlang or something.
|
# ? Nov 23, 2016 12:41 |
|
redleader posted:whoops i just wasted minutes of my life on this planet trying to find what the c++ spec means by "ill-formed" for some reason lomarf the standard posted:ill-formed program the standard posted:well-formed program leper khan fucked around with this message at 13:48 on Nov 23, 2016 |
# ? Nov 23, 2016 13:45 |
|
oh you're just learning to program, why dont you check out erlang or <OBSCURE ML VARIANT>
|
# ? Nov 23, 2016 13:50 |
|
CRIP EATIN BREAD posted:oh you're just learning to program, why dont you check out erlang or <OBSCURE ML VARIANT> an unironically good idea
|
# ? Nov 23, 2016 13:54 |
|
it's a good idea to check a bunch of paradigms when you're feeling somewhat solid on your current ground just to see what else is out there and figuring out different ways to think about problems. Starting in any paradigm isn't too bad as long as you're going to look at other stuff sooner than later to avoid walling yourself up.
|
# ? Nov 23, 2016 14:11 |
|
CRIP EATIN BREAD posted:oh you're just learning to program, why dont you check out erlang or <OBSCURE ML VARIANT> consider this hosed up world tho: many computer degrees start students that know nothing off with c++ or Java
|
# ? Nov 23, 2016 14:15 |
|
ThePeavstenator posted:consider this hosed up world tho: back in university we started off with a toy assembler and C. sophomore year we had a course using MIPS. good thing i already had a course using z80 in HS do the kids not still get exposure to the joys of assembly?
|
# ? Nov 23, 2016 14:24 |
|
CRIP EATIN BREAD posted:oh you're just learning to program, why dont you check out erlang or <OBSCURE ML VARIANT> Haskell would be a good first language, i agree. Or perhaps F#.
|
# ? Nov 23, 2016 14:27 |
|
no, actually the best first language is C64 basic because that is what i learned first and i turned out fine.
|
# ? Nov 23, 2016 14:42 |
|
Wheany posted:i turned out fine. uhhh
|
# ? Nov 23, 2016 14:50 |
|
leper khan posted:back in university we started off with a toy assembler and C. sophomore year we had a course using MIPS. I learned MIPS but I also go to a "good" school and am getting a 4 year degree. I don't see how it can be avoided in any CS-type degree tho.
|
# ? Nov 23, 2016 14:52 |
|
leper khan posted:back in university we started off with a toy assembler and C. sophomore year we had a course using MIPS. my Computer Organization class in the mid 00s was all MIPS. the book was all diagrams of a MIPS chip and our assembly assignments were in a simulator for it. then a few semesters later we had to build our own personal compiler that output MIPS assembly. i didn't go to a prestigious school but the CS department seemed pretty on-point with teaching the basics and building on previous classes as you went along we did use Java most of the time, but they chose it because "it's free, runs on everything, and for our courses everything will run identically", rather than for any fad reason. more than one of the long-time profs there told us stories about the bad old days when they got stuck with having to use some compiler package that cost a bunch of money, and the sales bullet point of "oh yeah this is identical across operating systems" was great until students bought copies for their home pcs/macs and whoops guess there are some subtle differences lol
|
# ? Nov 23, 2016 15:29 |
|
Bloody posted:ugh fine here's one partial Verilog implementation I did this while very drunk and only see one error (the fizz and buzz can't be reset in there) and only a few design niggles
|
# ? Nov 23, 2016 15:49 |
|
VikingofRock posted:So I've been searching around some more and I'm becoming increasingly convinced that in C, recursive calls to main() are actually legal. I'm curious what the various compiler writers in this thread have to say about it though (I forget if you are one of them, so apologies if you are--I just remember you as one of the people who probably knows much more C/C++ than me). gcc, on some architectures, notably windows, injects a call to _main at the beginning of main. _main runs things like static constructors on platforms that don't natively support static constructors in the executable format. depending on how it's implemented, it may not like being called twice
|
# ? Nov 23, 2016 15:56 |
|
my ST and Amiga C compilers do the same, main is preceded by a call to _main which runs a bunch of setup code so you don't need boilerplate crap in every program
|
# ? Nov 23, 2016 15:57 |
|
c c++14 s: why don't queue and stack have a method to pop/dequeue and move the value?
|
# ? Nov 23, 2016 16:20 |
|
VikingofRock posted:So I've been searching around some more and I'm becoming increasingly convinced that in C, recursive calls to main() are actually legal. I think you're right - I looked though all the references to main() in C90 / C99 / C11 and didn't see anything barring it.
|
# ? Nov 23, 2016 16:34 |
|
hackbunny posted:c c++14 s: why don't queue and stack have a method to pop/dequeue and move the value? I could tell you, but then I would have to kill you. Is there a reason you cannot move from front()/top() and then pop?
|
# ? Nov 23, 2016 16:35 |
|
|
# ? May 24, 2024 16:38 |
|
hackbunny posted:c c++14 s: why don't queue and stack have a method to pop/dequeue and move the value? can someone explain this meme to me? its clearly from before my time
|
# ? Nov 23, 2016 16:48 |