- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
#include <iostream>
using namespace std;
void wtf() {
return 0;
}
int main() {
return wtf();
cout << wtf();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−3
#include <iostream>
using namespace std;
void wtf() {
return 0;
}
int main() {
return wtf();
cout << wtf();
}
Решил нопейсать ватафак-код.
Классика жанра. Ретурн в воидовской функции. Плюс действие после ретурна.
0
https://www.youtube.com/watch?v=UcO6OXVZGyI
Можно промотать в конец.
0
#include <iostream>
#include <memory>
#include <thread>
#include <chrono>
#include <mutex>
struct Base
{
Base() { std::cout << " Base::Base()\n"; }
// Note: non-virtual destructor is OK here
~Base() { std::cout << " Base::~Base()\n"; }
};
struct Derived: public Base
{
Derived() { std::cout << " Derived::Derived()\n"; }
~Derived() { std::cout << " Derived::~Derived()\n"; }
};
void thr(std::shared_ptr<Base> p)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
std::shared_ptr<Base> lp = p; // thread-safe, even though the
// shared use_count is incremented
{
static std::mutex io_mutex;
std::lock_guard<std::mutex> lk(io_mutex);
std::cout << "local pointer in a thread:\n"
<< " lp.get() = " << lp.get()
<< ", lp.use_count() = " << lp.use_count() << '\n';
}
}
int main()
{
std::shared_ptr<Base> p = std::make_shared<Derived>();
std::cout << "Created a shared Derived (as a pointer to Base)\n"
<< " p.get() = " << p.get()
<< ", p.use_count() = " << p.use_count() << '\n';
std::thread t1(thr, p), t2(thr, p), t3(thr, p);
p.reset(); // release ownership from main
std::cout << "Shared ownership between 3 threads and released\n"
<< "ownership from main:\n"
<< " p.get() = " << p.get()
<< ", p.use_count() = " << p.use_count() << '\n';
t1.join(); t2.join(); t3.join();
std::cout << "All threads completed, the last one deleted Derived\n";
}
https://en.cppreference.com/w/cpp/memory/shared_ptr
Объясните почему "reset" не грохнул инстанс в других потоках?
−1
Давайте хвалить "C++"
https://m.vk.com/video-72495085_456239260?list=e8cb53a2003660e817&from=wall-72495085_852669
−4
#include <iostream>
using namespace std;
int main()
{
cout<<"My first govnokod"<<endl;
}
+1
// Non-constant constant-expressions in C++
// http://b.atch.se/posts/non-constant-constant-expressions/
// The Implementation
constexpr int flag (int);
template<class Tag>
struct writer {
friend constexpr int flag (Tag) {
return 0;
}
};
template<bool B, class Tag = int>
struct dependent_writer : writer<Tag> { };
template<
bool B = noexcept (flag (0)),
int = sizeof (dependent_writer<B>)
>
constexpr int f () {
return B;
}
int main () {
constexpr int a = f ();
constexpr int b = f ();
static_assert (a != b, "fail");
}
Note: clang incorrectly shows the wrong behavior, a workaround is available in the appendix.
0
// https://habr.com/company/JetBrains/blog/249479/
Привет, Хабр!
Некоторое время назад мы объявили конкурс — требовалось продолжить фразу:
Бьёрн Страуструп создал С++ 36 лет назад, и он до сих пор востребован и пользуется популярностью у разработчиков, потому что...
Спасибо всем участникам за массу положительных эмоций и разнообразные предположения о том, что же сделало C++ таким популярным.
Посовещавшись, мы выбрали топ-6 ответов:
+1
// https://habr.com/post/417027/
// Как я стандартную библиотеку C++11 писал или почему boost такой страшный
// https://github.com/oktonion/stdex/blob/1472fd5e2f5e0d10a136518631055c3aad2e1cfd/stdex/include/thread.hpp#L51
template<class R, class T1>
struct _function_traits<R(*)(T1)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T1 argument_type;
};
template<class R, class T1, class T2>
struct _function_traits<R(*)(T1, T2)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
};
template<class R, class T1, class T2, class T3>
struct _function_traits<R(*)(T1, T2, T3)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
};
template<class R, class T1, class T2, class T3, class T4>
struct _function_traits<R(*)(T1, T2, T3, T4)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
};
template<class R, class T1, class T2, class T3, class T4,
class T5>
struct _function_traits<R(*)(T1, T2, T3, T4, T5)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
};
template<class R, class T1, class T2, class T3, class T4,
class T5, class T6>
struct _function_traits<R(*)(T1, T2, T3, T4, T5, T6)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
};
template<class R, class T1, class T2, class T3, class T4,
class T5, class T6, class T7>
struct _function_traits<R(*)(T1, T2, T3, T4, T5, T6, T7)>
{
typedef R result_type;
typedef T1 arg1_type;
typedef T2 arg2_type;
typedef T3 arg3_type;
typedef T4 arg4_type;
typedef T5 arg5_type;
typedef T6 arg6_type;
typedef T7 arg7_type;
};
...
> На дворе был 2017 год! Уже C++ 17 активно вводился в GCC, clang, Visual Studio, везде был decltype (since C++ 11), constexpr (since C++ 11, но существенно доработан), модули уже почти на подходе, хорошее время было. Я же находился на работе и с некоторым неодобрением смотрел на очередной Internal Compiler Error в своем Borland C++ Builder 6.0, а так же на множество ошибок сборки с очередной версией библиотеки boost. Думаю, теперь вы понимаете, откуда взялась эта тяга к велосипедостроению. У нас использовался Borland C++ Builder 6.0 и Visual Studio 2010 под Windows, g++ версии 4.4.2 или ниже под QNX и под некоторые unix системы. От MacOS мы были избавлены, что несомненно было плюсом. Ни о каких других компиляторах (под C++ 11 в том числе) речи даже быть не могло по соображениям, которые мы оставим за пределами данной статьи.
> «А что там может быть на столько сложного» — закралась мысль в мой измученный попытками завести boost под старый-добрый builder мозг. «Мне всего то нужно type_traits, thread, mutex, возможно chrono, nullptr было бы еще неплохо.» — рассудил я и принялся за работу.
0
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
void test1(void)
{
printf("test1\n");
}
void test2(void)
{
printf("test2\n");
}
void test3(void)
{
printf("test3\n");
}
void test4(void)
{
printf("test4\n");
}
uint8_t func_dist[3] = {(uint8_t)((char *)test2-(char *)test1), (uint8_t)((char *)test3-(char *)test2), (uint8_t)((char *)test4-(char *)test3)};
void callf(uint8_t fn)
{
size_t sum_dis = 0;
for (uint8_t i = 0; i < fn; i++)
{
sum_dis += func_dist[i];
}
( (void(*)(void)) ((char *)test1+sum_dis) ) ();
}
int main(void)
{
callf(0);
callf(1);
callf(2);
callf(3);
return EXIT_SUCCESS;
}
Зожатие указателей. Главное чтоб длины функций не превышали 255 и чтоб функции шли строго подряд, как они объявлены кода
Как сделать чтобы это компилировалось сишкой?
0
body {background: url("http://forumfiles.ru/files/0008/ea/f4/23438.jpg") repeat-y scroll center top transparent;}
#logotop {background-image: url("http://forumfiles.ru/files/0008/ea/f4/46264.png"); margin-left: -33px;}
#pun {background-image: url("http://forumfiles.ru/files/0008/ea/f4/21620.jpg");}
.punbb .section .container, .punbb .post-body, .punbb .post-links, .punbb td.tc2, .punbb td.tc3, .punbb .formal fieldset .post-box, #viewprofile li strong, #viewprofile li div, #setmods dd, .punbb .info-box, .punbb #pun-main .info-box .legend {color: #777;}
.punbb .post h3 span, .punbb th, #viewprofile li, #setmods dl {color: #777;}
Северянин