steinkrauz - Пора на свалку, на свалку пора

> Recent Entries
> Archive
> Friends
> User Info

December 10th, 2019


Previous Entry Add to Memories Tell A Friend Next Entry
08:24 pm - Пора на свалку, на свалку пора
Знаете, что забавно в этом примере? Нет, не то, что там элементарная ошибка. А то, что компилятор из этого вполне себе создаст исполняемый файл. Варнинг, конечно, будет, и для этого примера отлично виден. Только вот когда проект большой, поймать новое сообщение в летящей простыне вывода практически невозможно.

#include <iostream>
#include <algorithm>
#include <vector>

std::vector<int> make(size_t size)
{
	std::vector<int> res;
	for (size_t i; i<size; i++)
		res.push_back(size-i);
	std::sort(res.begin(), res.end());
}

int main(int argc, char *argv[])
{
	std::vector<int> data = make(5);
	for (int i:data)
		std::cout<<i<<" ";
	std::cout<<"\n";
	return 0;
}


Угу, это по результатам сегодняшних приключений, когда час бился головой об стенку, не понимая, с какого перепуга обращение к std::string даёт ошибку генерала Фолта.

CPP PEDIBUS DESTRUE!

(20 comments | Leave a comment)

Comments:


[User Picture]
From:[info]sadkov
Date:December 10th, 2019 - 04:49 pm
(Link)
>using C++ in 21st century.

Russians must suffer.
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 05:32 pm
(Link)
no-no-no..c++ very nice lang
[User Picture]
From:[info]sadkov
Date:December 10th, 2019 - 05:41 pm
(Link)
suffer.
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 06:54 pm
(Link)
ok. I will suffer. What namelly and pointelly lang is not "suffer" and so effective (i mean speed) and low numbers of levels of abstractions from hardware?
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 05:33 pm
(Link)
question: what result return make function? nullptr?
[User Picture]
From:[info]sadkov
Date:December 10th, 2019 - 05:45 pm
(Link)
The result is undefined. Because C++ allows undefined results.
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 07:05 pm
(Link)
if you will engage suicide,
you need to have this capability,
always
[User Picture]
From:[info]steinkrauz
Date:December 10th, 2019 - 06:41 pm
(Link)
The function will return whatever garbage a complier would decide to put in.
The Undefined Behaviour in all its ugly glory.
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 07:03 pm
(Link)
no.
it's just "poorly programmad "indussian" " code
hehehe
[User Picture]
From:[info]steinkrauz
Date:December 10th, 2019 - 07:31 pm
(Link)
You're wrong:
6.6.3(2): Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function.
(Emphasis is mine).


[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 08:02 pm
(Link)
yes-yes-yes. OK!

I think programmers need new c++ -- new "L4 runic language"
-- W0RN COMPILER.
(but it will emit code so effective like C/C++)
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 05:36 pm
(Link)
or not include < string > ?
[User Picture]
From:[info]steinkrauz
Date:December 10th, 2019 - 06:42 pm
(Link)
I do not use any strings here, so no need to incude this header.
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 06:59 pm
(Link)


std::cout << i << " ";
std::cout<<"\n";


sorry, if i wrong, i'm not in "programmers mode" right now.
(in literature writer mode)
[User Picture]
From:[info]steinkrauz
Date:December 10th, 2019 - 07:37 pm
(Link)
Those are 'string literals' and they have 'const char *' type';
[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 07:07 pm
(Link)
(you use vectro of char, ok.
but i do not sure, that it's supports by stream. or some kind of manipulators need to be used)
[User Picture]
From:[info]steinkrauz
Date:December 10th, 2019 - 07:39 pm
(Link)
No need for any manipulations. ostream MUST implement this operator:
template
basic_ostream
[Error: Irreparable invalid markup ('<char,traits>') in entry. Owner must fix manually. Raw contents below.]

No need for any manipulations. ostream MUST implement this operator:
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out,
const char* s);
(As per 27.6.2.5.4)
From:(Anonymous)
Date:December 10th, 2019 - 07:13 pm
(Link)
все программисты — гомосексуалисты; это вытекает из самой сущности программирования.

[User Picture]
From:[info]wieiner_
Date:December 10th, 2019 - 08:03 pm
(Link)
не
вынепгавы
From:(Anonymous)
Date:December 10th, 2019 - 08:32 pm
(Link)
Кабинку обмерил уже, говномер?

> Go to Top
LJ.Rossia.org