[–]▶ No.811729>>811730 >>811737 >>811764 >>811766 >>811771 >>811773 >>811778 >>811809 >>812109 >>812183 >>813764 >>814011 >>828294 >>828563 [Watch Thread][Show All Posts]
int main() {
std::string s;
int n = 5 / 2;
std::cout << n << "\n";
}
>doesnt warn about unused s
>doesnt warn about loss of information when truncating to int
great compiler you got there lads
▶ No.811730
▶ No.811731>>811767
>>doesnt warn about unused s
Looks like it's the same for clang. Pretty strange, since
#include <stdio.h>
int main(void) {
char *s;
int n = 5 / 2;
printf("%d\n", n);
return 0;
}
gives a unused variable ‘s’ warning. Must be because C++ is for faggots.
>>doesnt warn about loss of information when truncating to int
Truncating what to int, retard? It's an integer division.
▶ No.811764>>811767 >>828563
>>811729 (OP)
>doesnt warn about loss of information when truncating to int
What loss? Integer division is truncating the remainder by design, if you do integer division it's assumed you want the remainder to be truncated.
▶ No.811766>>811767 >>811771
>>811729 (OP)
gcc is for commie faggots
use clang
▶ No.811767>>811769
>>811731
i'll bet you it compiles it out anyway.
>>811764
this
>>811766
meme license that doesn't even require the source to be made available
https://en.wikipedia.org/wiki/Category:Software_using_the_NCSA_license
▶ No.811769
>>811767
meme license is better than meme license+messy code
▶ No.811771>>811806
>>811729 (OP)
Did you use -Wall -Wextra?
>>811766
>use clang
In the words of Scott Meyers, is there a Windows package for it, faggot? An official standalone distro that doesn't require either Visual Studio or GCC to be installed? One that comes bundled with stdc++ out of the box?
▶ No.811773
>>811729 (OP)
It can warn you, you have to enable verbose warnings when compiling.
int round down is a great thing, considering you can always get the remainder with a %.
▶ No.811778>>811807
>>811729 (OP)
your shitty bait doesnt even compile
https://godbolt.org/g/AAS6CA
▶ No.811806>>814017
>>811771
-Wall -Wextra -pedantic -O2
▶ No.811807>>811808
>>811778
You can't catch bait with bait.
▶ No.811808>>811810
>>811807
are you saying that im baiting? because i most assuredly am not. i just popped what op posted into godbolt and it doesnt compile.
▶ No.811809>>813676
>>811729 (OP)
std::string isn't unused. It has a non-trivial constructor that can throw. Welcome to C++.
▶ No.811810>>811811 >>813715
>>811808
Better to claim you were pretending to be retarded than just being retarded.
#include <string>
#include <iostream>
int main() {
std::string s;
int n = 5 / 2;
std::cout << n << "\n";
}
▶ No.811811>>811812 >>811813 >>828560
>>811810
>not knowing c++ makes you a retard
ok fag
▶ No.811812>>811815
>>811811
>claiming something doesn't work despite being clueless of if it's communicating anything to other programmers
Yeah, you're retarded. Just stay out of discussions you have no clue about.
▶ No.811813>>811815
>>811811
>acts retarded
>claims not to be a retard
ok
▶ No.811815>>811817 >>811822
>>811813
>>811812
>samefagging
please tell me why op didnt just post working code???
▶ No.811818>>812103
>>811817
nice photoshoop fag
▶ No.811822>>811824 >>812103
>>811820 (You)
>>811815 (You)
Here are your (You)s
▶ No.811823>>811824 >>813736
Why are the shittiest threads and comments when Europe is awake?
▶ No.811824
>>811822
thx
>>811823
because i, steve klabnik am a europoor
▶ No.811891
>>doesnt warn about loss of information when truncating to int
I don't see any truncation to int here. You're taking two integers and performing integer division on them, giving you an integer. Where's the problem?
▶ No.812103
>>811822
>>811820
>>811818
>>811817
Christ, this is why /tech/ needs ID's.
▶ No.812109
▶ No.812183>>812188
>>811729 (OP)
>doesn't know how to turn on unused variable warnings
>thinks default behavior of integer division is something you need to be warned about
Did you just start your first programming course this semester, OP, or are you just that dumb that you think we'd fall for this bait.
▶ No.812857>>812874 >>812880
Want something even more retarded?
#include <stdio.h>
int
main(void)
{
char s[2];
fgets(s, 1, stdin);
return 0;
}
No warning with -Wall -Wextra.
Warning with -O1 without -Wall and -Wextra.
▶ No.812859
int main() {
char s[1];
gets(s);
return *s;
}
▶ No.812874>>812904 >>812991
>>812857
>reddit spacing
>even in the code
wow im hyper triggered
▶ No.812880>>812991
>>812857
I don't get it, what's wrong with it, reddit friend?
▶ No.812904>>812908
>>812874
I think the whole "reddit spacing" meme is retarded, but if you feel as annoyed as I do when I see code like that, I understand. I'm sorry I used to hate you ">reddit-spacing" autists, I understand now. I'll continue separating paragraphs with blank lines though.. just squint your eyes and it'll look all cramped up again.
▶ No.812908>>813081
▶ No.812991>>813076
>>812874
>>812880
Actually, that's 8chan fucking up my copy-pasted code. Now, do you have an argument, my sweet sweet 9GAG memers?
▶ No.813076>>813216
▶ No.813081
>>812908
I'm not going to change how I type my posts just so your custom style sheet looks better.
▶ No.813216
>>813076
I'll take that as a no. Thank you, 9GAG.
▶ No.813676>>813702
>>811809
Interesting can you explain?
▶ No.813683
▶ No.813702>>813718
>>813676
classes with constructors can have side-effects, so you can't just elide these "unused" variables as they actually did something that might change program execution, unless the compiler can detect the constructor does nothing. Who knows what std::string's constructor is actually doing as it changes so often, but the compiler is apparently confident that it has some possible side-effect so has left it in.
▶ No.813715>>813719
>>811810
>using iostream
just use stdio.h in C++. avoid the cancer.
▶ No.813718
>>813702
(((the compiler)))
a great unknown entity
▶ No.813719>>813727
>>813715
whats so bad about iostream? speed seems to be the same as printexploitf
▶ No.813727>>813742 >>813743 >>826250
>>813719
>speed seems to be the same as printexploitf
In what universe?
#ifdef SEPPLES
#include <iostream>
#else
#include <stdio.h>
#endif
int main(int argc, char *argv[]) {
volatile int a = 1;
volatile char b = 'b';
for(int i = 0; i < 1000000; ++i) {
#ifdef SEPPLES
std::cout << "a number: " << i << ", a letter: " << b << ", a nothing:" << std::endl;
#else
printf("a number: %d, a letter: %c, a nothing:\n", a, b);
#endif
}
}
[code]
To /dev/null, C:
[code]
real 0m0.056s
user 0m0.052s
sys 0m0.000s
SheePrusPrus:
real 0m0.294s
user 0m0.140s
sys 0m0.152s
Bonus: Try internationalizing the C++ version. You fucking can't. It's also much larger and also is shit. strings and streams are the worst parts of C++ and should be avoided as much as possible.
▶ No.813736
>>811823
Because that also means eastern europe is also awake
▶ No.813742>>813753
>>813727
Actually, IOStreams don't have to be slow! It is a matter of implementing them in a reasonable way to make them fast, though. Most standard C++ library don't seem to pay too much attention to implement IOStreams. A long time ago when my CXXRT was still maintained it was about as fast as stdio - when used correctly!
Note that there are few performance traps for users laid out with IOStreams, however. The following guidelines apply to all IOStream implementations but especially to those which are tailored to be fast:
1. When using std::cin, std::cout, etc. you need to call std::sync_with_stdio(false)! Without this call, any use of the standard stream objects is required to synchronize with C's standard streams. Of course, when using std::sync_with_stdio(false) it is assumed that you don't mix std::cin with stdin, std::cout with stdout, etc.
2. Do not use std::endl as it mandates many unnecessary flushes of any buffer. Likewise, don't set std::ios_base::unitbuf or use std::flush unnecessarily.
3. When creating your own stream buffers (OK, few users do), make sure they do use an internal buffer! Processing individual characters jumps through multiple conditions and a virtual function which makes it hideously slow.
▶ No.813743>>813756 >>828266
>>813727
>0.294s
>0.140s
fuck that's slower than python
$ cat shit.py
def main():
a=1
b='a'
print "a number: "+str(1)+", a letter: "+b+", a nothing:"
if __name__=="__main__":
main()
$ time python2.7 shit.py
a number: 1, a letter: a, a nothing:
real 0m0.019s
user 0m0.012s
sys 0m0.004s
▶ No.813753
>>813742
>Actually, IOStreams don't have to be slow! It is a matter of implementing them in a reasonable way to make them fast, though.
No, they have to be slow without breaking the standard. The issue is baked into the design. Check out xsputn, for example. All these low-level streambuf functions were defined virtual as people had a hard-on for OOP at the time and templates weren't a fully fleshed out concept both in terms of code and how people thought of their use. The result is code any compliant C++ compiler can never optimize away and a lot of pointless calls.
We need a compete redesign of the strings/streams layer in C++. And also for exception::what() to return a string so you don't have to pay the cost of generating a string people will likely never request or hacking it with a mutable.
▶ No.813756
>>813743
The C++ version prints 1,000,000 times. However, the python version modified to print that many times is still actually almost as fast as C++.
def main():
for i in xrange(1000000):
a=1
b='a'
print "a number: "+str(1)+", a letter: "+b+", a nothing:"
if __name__=="__main__":
main()
real 0m0.314s
user 0m0.312s
sys 0m0.000s
This is why people say to avoid this shit in C++.
▶ No.813764>>813977 >>814017 >>822162
>>811729 (OP)
it doesn't faggot, because you didn't give compilation flags, fuck off piece of shit
▶ No.813977>>814849
>>813764
>compilation flags have been named in the thread
>hurr durr let me just bust in here and pretend i know shit when im just another retarded faggot
holy shit kys
▶ No.814000
>>813996
Wow omg shes so cute ^^
Using clang from now on!
▶ No.814011>>814017
>>811729 (OP)
>what is -Wall -Wextra -Werror -pedantic
>what is integer division
Delete this shit thread.
▶ No.814017
>>813764
>>814011
see >>811806
i understand you want to show off your retardation but this is too much
▶ No.814027
>>812809
kek
sage for shit thread anyway
▶ No.814849
>>813977
OP didn't mention that, you retard, apparently there needs to be several posts about something to get people actually realize the thing
▶ No.820949
<the state of /tech/ in late 2017
▶ No.822162
>>813764
How could anyone get mad like this over such a thing.
▶ No.826250>>828327
>>813727
>making a variable that's already used volatile for benchmarking
▶ No.828294
>>811729 (OP)
>>doesnt warn about loss of information when truncating to int
> thinks that all arithmetic is done in floating point
> pajeet detected
▶ No.828327
>>826250
Making it volatile prevents the compiler potentially optimizing away a lot of the code. Two files could have been used instead where one calls the other and passes the values to similarly prevent cheating.
▶ No.828552>>828554
>>811816
>When you don't understand booleans
▶ No.828554
>>828552
Surely gender is an enum.
▶ No.828560
>>811811
>not knowing c++ makes you a retard
But it does.
▶ No.828563>>828575 >>828651
>>811729 (OP)
>>811764
What I'm personally pissed about (C++, not the compiler) is it doesn't warn about integer overflow or underflow.
t. large numbers fag.
#include<iostream>
using namespace std;
int main(){
int a1 = 319746;
int a2 = 619692056;
int fuckMe = a1*a2/a2;
cout<<a1<<" "<<a2<<" "<<fuckMe<<"\n";}
▶ No.828575
>>828563
The compiler isn't going to wipe your ass for you when it comes to mathematical bounds and precision, you need to know how to use numbers. You're in for a shock when you start using floats.
▶ No.828651