Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
CPColin
Sep 9, 2003

Big ol' smile.

Wheany posted:

no, actually the best first language is C64 basic because that is what i learned first and i turned out fine.

This except Tandy TRS-80 BASIC.

Adbot
ADBOT LOVES YOU

Sapozhnik
Jan 2, 2005

Nap Ghost

LeftistMuslimObama posted:

can someone explain this meme to me? its clearly from before my time

c foo s => current foo status (from cjs thread which doesn't actually stand for computer janitors contrary to popular belief)

also uh that _main thing is stupid. every compiler i know of has a C Runtime object that exports a __start label, program execution begins there and it is __start that is responsible for calling main

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Xarn posted:

I could tell you, but then I would have to kill you. :v:

Is there a reason you cannot move from front()/top() and then pop?

that's what I'm doing! but it's stupid, I want a method that does both. compare expectation:

return stack.pop();

reality:

auto value = std::move(stack.top());
stack.pop();
return value;

Sapozhnik posted:

also uh that _main thing is stupid. every compiler i know of has a C Runtime object that exports a __start label, program execution begins there and it is __start that is responsible for calling main

gcc was ported to windows in a very stupid way. the greatest irony is that the dos port was a better windows compiler than the windows port

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

hackbunny posted:

that's what I'm doing! but it's stupid, I want a method that does both. compare expectation:

return stack.pop();

reality:

auto value = std::move(stack.top());
stack.pop();
return value;

they probably don't want to hide the fact that the "TopPop" method would have to implicitly make a copy somewhere to return the value, or use an r-value constructor

also, there might be some issues with exception safety guarantees

Xarn
Jun 26, 2015

hackbunny posted:

that's what I'm doing! but it's stupid, I want a method that does both. compare expectation:

return stack.pop();

reality:

auto value = std::move(stack.top());
stack.pop();
return value;


gcc was ported to windows in a very stupid way. the greatest irony is that the dos port was a better windows compiler than the windows port

More serious answer then:

In C++98, you could either have exception safety or convenient API, because if you had something like
C++ code:
T Stack<T>::pop(){
    if (empty()) {
        throw "stop using empty stack dumbass";
    }
    return elems[top--];
}
what happens when copy constructor throws? You either get into an inconsistent state, or throw away data, because top has been decreased, but the element wasn't copied out. You can try various tricks to solve this, but fundamentally, in a world without noexcept moves, you have to split to split remove-and-return-value into return, remove. This is the reason behind the current stack/queue interface.

Now, in a world with noexcept move, you could do a bit of template magic and make pop move return T iff T has no-except moves, similarly to map::find (which can take comparable types, not just the Key type, if the comparator supports it), but nobody bothered. Also it would be kinda weird and confusing to have different return types depending on the templated-upon type.

I guess you can make a standardization paper, there have been some interesting container interface changes lately so this might pass as well.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
windows executables do have static initializers but they're badly named and you can easily miss them. I won't blame you if you do because even microsoft missed it. what you have to do is add a tls directory with a list of callbacks, callbacks are identical to dllmain but with a void return value (ie. they can't veto thread creation), so they get called at process creation, thread creation, thread exit and process exit. microsoft themselves forgot about it and so you get things like _beginthread/_endthread because duh the main executable doesn't have a dllmain and doesn't get thread notifications! and if I add a tls directory the module can't be loaded dynamically :ohdear: except of course, imbeciles, the main executable is always loaded statically. another aspect of windows development that borland understood better than microsoft

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Xarn posted:

More serious answer then:

in an implementation like this:

// e: maybe I should use std::move_if_noexcept here so that a failed move doesn't leave a corrupted object in the stack
auto value = std::move(stack.top());
stack.pop();
return value;

isn't the "return value" line guaranteed to be non-throwing, by now? because the return value is not copied or moved but constructed in its final place. or is it still just an optional optimization?

Xarn posted:

I guess you can make a standardization paper, there have been some interesting container interface changes lately so this might pass as well.

I don't know if I know the standard well enough to make a proposal

hackbunny fucked around with this message at 17:49 on Nov 23, 2016

Xarn
Jun 26, 2015

hackbunny posted:

in an implementation like this:

// e: maybe I should use std::move_if_noexcept here so that a failed move doesn't leave a corrupted object in the stack
auto value = std::move(stack.top());
stack.pop();
return value;

isn't the "return value" line guaranteed to be non-throwing, by now? because the return value is not copied or moved but constructed in its final place. or is it still just an optional optimization?

In C++14 its still only optional optimization. In C++17... dunno, didn't really bother looking up the proposed rules for guaranteed copy elision yet, but I think its for cases where RVO was supposed to kick in (and not NRVO).

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

Sapozhnik posted:

c foo s => current foo status (from cjs thread which doesn't actually stand for computer janitors contrary to popular belief)

to expand this a bit: one of the original computer-janitor chat threads was called "current job status" (i.e. CJS). people began making posts where they would share some dumb thing they had to do at work that day, written (for example) like "cjs: scraping boogers off the underside of the desk that belonged to the guy who just got fired" or "cjs: reimaging bob's machine for the third time this week because he can't help but click on phishing emails". this "joke" was then generalized to the form of "c<something>s: <example in the 'something' category>". so in the post LMO quoted the "c c++14 s:" expands to "current c++14 status: <thing about lol why is c++14 so dumb>"

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Xarn posted:

In C++14 its still only optional optimization. In C++17... dunno, didn't really bother looking up the proposed rules for guaranteed copy elision yet, but I think its for cases where RVO was supposed to kick in (and not NRVO).

this is horrible, you're telling me there's no safe way to modify a container and return a value from it. short of explicitly returning the value through a by reference argument I guess

Weekend Bridges
Apr 8, 2015

by Smythe

Lutha Mahtin posted:

to expand this a bit: one of the original computer-janitor chat threads was called "current job status" (i.e. CJS). people began making posts where they would share some dumb thing they had to do at work that day, written (for example) like "cjs: scraping boogers off the underside of the desk that belonged to the guy who just got fired" or "cjs: reimaging bob's machine for the third time this week because he can't help but click on phishing emails". this "joke" was then generalized to the form of "c<something>s: <example in the 'something' category>". so in the post LMO quoted the "c c++14 s:" expands to "current c++14 status: <thing about lol why is c++14 so dumb>"

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Lutha Mahtin posted:

to expand this a bit: one of the original computer-janitor chat threads was called "current job status" (i.e. CJS). people began making posts where they would share some dumb thing they had to do at work that day, written (for example) like "cjs: scraping boogers off the underside of the desk that belonged to the guy who just got fired" or "cjs: reimaging bob's machine for the third time this week because he can't help but click on phishing emails". this "joke" was then generalized to the form of "c<something>s: <example in the 'something' category>". so in the post LMO quoted the "c c++14 s:" expands to "current c++14 status: <thing about lol why is c++14 so dumb>"

did you really just write this all out

Xarn
Jun 26, 2015

hackbunny posted:

this is horrible, you're telling me there's no safe way to modify a container and return a value from it. short of explicitly returning the value through a by reference argument I guess

Yep, if you can't place any constraints on types (like "has noexcept moves, because we are not savages"), then you have to either change the interface, or not be exception safe.

Depending on your use case, you could change the API, like this
C++ code:
auto ptr = std::make_unique<T>(std::move_if_noexcept(stack.top()));
stack.pop();
return ptr;
so that you can always have the noexcept return guarantee.

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal
if someone in this thread does end up submitting a proposal for a "move and pop" method, please follow standard yospos conventions and name it poop()

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Xarn posted:

Yep, if you can't place any constraints on types (like "has noexcept moves, because we are not savages"), then you have to either change the interface, or not be exception safe.

Depending on your use case, you could change the API, like this
C++ code:
auto ptr = std::make_unique<T>(std::move_if_noexcept(stack.top()));
stack.pop();
return ptr;
so that you can always have the noexcept return guarantee.

:barf:

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
seems easier to just remove the method if the value isn't nothrow movable

C++ code:
std::enable_if_t<std::is_nothrow_move_constructible<value_type>::value, value_type> poop()
{
	value_type value{ std::move(top()) }; // explicit nothrow move
	pop();
	return value; // implicit nothrow move or rvo
}
hopefully encouraging people (= fucktards) to avoid writing non-nothrow moves

hackbunny fucked around with this message at 21:18 on Nov 23, 2016

VikingofRock
Aug 24, 2008




So how does noexcept work? It's sort of like const-correctness in that you have to explicitly state it for each function, right? But unlike const-correctness the compiler can't catch noexcept mistakes for you?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

VikingofRock posted:

So how does noexcept work? It's sort of like const-correctness in that you have to explicitly state it for each function, right? But unlike const-correctness the compiler can't catch noexcept mistakes for you?

throwing out of a noexcept function calls std::terminate. it's sort of the opposite of const in that it gives well-defined semantics to bad code rather than trying to help the compiler catch bad code with undefined results if you bypass it.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

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

in practice it means that you have written something which is not a valid c++ program but which a compiler will probably accept without complaint

qntm
Jun 17, 2009

Plorkyeran posted:

in practice it means that you have written something which is not a valid c++ program but which a compiler will probably accept without complaint

seems to me that the compiler should probably reject invalid programs

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

qntm posted:

seems to me that the compiler should probably reject invalid programs
but then there wouldn't be any programs left

qntm
Jun 17, 2009

anthonypants posted:

but then there wouldn't be any programs left

works as designed

VikingofRock
Aug 24, 2008




qntm posted:

seems to me that the compiler should probably reject invalid programs

I eagerly await the post that explains why this is equivalent to solving the halting problem or whatever.

redleader
Aug 18, 2005

Engage according to operational parameters
there must be at least some situations where a compiler could detect an ill-formed program and bail out - perhaps e.g. if someone tries to call main()?

Mao Zedong Thot
Oct 16, 2008


today i worked with some dudes that were not allowed to type 'rm -r' -- like if they typed those keys, even in an editor, it would log them out lmao

i was watching screenshare, so not poking around at it myself, but I wonder if they typed like 'rm<space><backspace><space>-<space><backspace><space>r' it wouldn't catch it lol

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

VOTE YES ON 69 posted:

today i worked with some dudes that were not allowed to type 'rm -r' -- like if they typed those keys, even in an editor, it would log them out lmao

i was watching screenshare, so not poking around at it myself, but I wonder if they typed like 'rm<space><backspace><space>-<space><backspace><space>r' it wouldn't catch it lol
or rm -fr

Mao Zedong Thot
Oct 16, 2008


i would guess that 'rm -f' was blocked too

but who knows

whoever thinks its important for employees to be subject to poo poo like that is maybe not the sharpest tool in the shed

gonadic io
Feb 16, 2011

>>=

VOTE YES ON 69 posted:

today i worked with some dudes that were not allowed to type 'rm -r' -- like if they typed those keys, even in an editor, it would log them out lmao

i was watching screenshare, so not poking around at it myself, but I wonder if they typed like 'rm<space><backspace><space>-<space><backspace><space>r' it wouldn't catch it lol

alias rem=rm

anthonypants
May 6, 2007

by Nyc_Tattoo
Dinosaur Gum

VOTE YES ON 69 posted:

i would guess that 'rm -f' was blocked too

but who knows

whoever thinks its important for employees to be subject to poo poo like that is maybe not the sharpest tool in the shed
ok then, rm --no-preserve-root -rf

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

VOTE YES ON 69 posted:

today i worked with some dudes that were not allowed to type 'rm -r' -- like if they typed those keys, even in an editor, it would log them out lmao

i was watching screenshare, so not poking around at it myself, but I wonder if they typed like 'rm<space><backspace><space>-<space><backspace><space>r' it wouldn't catch it lol

:stare:

Soricidus
Oct 21, 2010
freedom-hating statist shill
"oh yeah that's easy, just run transform -rotFUCK"

Mao Zedong Thot
Oct 16, 2008


i wish I had a shell on their system, would be fun to gently caress around with and see how abusable it is

code:
$ `python -c 'print "rm" + " -rf"'`
etc

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


i discovered a couple days before i left HS that one of our computer lab servers was configured to allow any user to run sudo nice

sudo nice bash would have been great fun if i weren't a pussy :(

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

redleader posted:

there must be at least some situations where a compiler could detect an ill-formed program and bail out - perhaps e.g. if someone tries to call main()?

yes, compiler errors are a thing that exist, and a lot of compiler warnings and static analyzer checks are for things that probably make a program ill-formed

VikingofRock posted:

I eagerly await the post that explains why this is equivalent to solving the halting problem or whatever.

if (program_halts()) { *((int *)0) = 0; }

VikingofRock
Aug 24, 2008




gonadic io posted:

alias rem=rm

install :rip:rip:rip:

my homie dhall
Dec 9, 2010

honey, oh please, it's just a machine

Plorkyeran posted:

if (program_halts()) { *((int *)0) = 0; }

I was thinking about this one.

I think you have to show that a program that would differentiate between a malformed and a 'proper' program would also solve the halting problem, right?

JewKiller 3000
Nov 28, 2006

by Lowtax

Ploft-shell crab posted:

I was thinking about this one.

I think you have to show that a program that would differentiate between a malformed and a 'proper' program would also solve the halting problem, right?

https://en.wikipedia.org/wiki/Rice%27s_theorem

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Ploft-shell crab posted:

I was thinking about this one.

I think you have to show that a program that would differentiate between a malformed and a 'proper' program would also solve the halting problem, right?

right, it should actually be if (program_is_well_formed()) { *((int *)0) = 0; } such that it's well-formed only if it isn't, since an ill-formed program neither halts nor doesn't halt

Deep Dish Fuckfest
Sep 6, 2006

Advanced
Computer Touching


Toilet Rascal

Plorkyeran posted:

right, it should actually be if (program_is_well_formed()) { *((int *)0) = 0; } such that it's well-formed only if it isn't, since an ill-formed program neither halts nor doesn't halt

wouldn't having that null pointer dereference make your program ill-formed regardless of whether you get to that clause or not, in the same way that having undefined behavior anywhere in your program invalidates the whole thing and not just what comes after?

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015

Deep Dish Fuckfest posted:

wouldn't having that null pointer dereference make your program ill-formed regardless of whether you get to that clause or not, in the same way that having undefined behavior anywhere in your program invalidates the whole thing and not just what comes after?

Undefined behaviour invalidates the path leading to it (and also any path following) and not the whole program.

Basically, with this code
C++ code:
int butts;
std::cin >> butts;
int poops = 123 / butts;
the compiler can assume that butts will not be zero and delete any branch assuming that butts could be zero. Another example is this
C++ code:
#include <iostream>
#include <iomanip>
 
int elements[] = {1, 2, 3, 4};
 
bool contains(int elem) {
    for (int i = 0; i <= 4; ++i) {
        if (elements[i] == elem) {
            return true;
        }
    }
    return false;
}
 
int main() {
	int num;
	while (std::cin >> num){
	    std::cout << std::boolalpha << contains(num) << '\n';
            std::cout << num << '\n';
	}
}
Where contains will return true regardless of actual input, because the only way to return false is to invoke undefined behaviour first. However, it is not allowed to remove the output, because it does not have to invoke UB to output.

  • Locked thread