- 1
- 2
- 3
- 4
- 5
- 6
#include <stdio.h>
int main(int argc, char* argv[]) {
scanf_s("%s", (char*)argv);
return 1;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
#include <stdio.h>
int main(int argc, char* argv[]) {
scanf_s("%s", (char*)argv);
return 1;
}
Нашел у себя в какой-то папке Memecode Junks 2014 года, не помню зачем это там. Но выглядит весело =))
0
typedef struct {
std::shared_ptr<char*>my_arr;
}MyInputs;
...
std::shared_ptr<MyInputs> MainDoc (static_cast<MyInputs*>(malloc(sizeof (*MainDoc))),free);
std::shared_ptr<char*> Z (static_cast<char**>(malloc(sizeof (**MainDoc->my_arr) * 10)),free);
std::shared_ptr<char> Z[0](static_cast<char*>(malloc(sizeof (char *) * 10)),free);
memcpy(Z[0].get(), (char*)"salut\0", 6);
cout << Z[0] << endl;
...
https://stackoverflow.com/questions/27201555/c-array-of-shared-ptr
0
#include <clcpp/clcpp.h>
#include <clcpp/FunctionCall.h>
// Reflect the entire namespace and implement each class
clcpp_reflect(TestClassImpl)
namespace TestClassImpl
{
class A
{
public:
A()
{
x = 1;
y = 2;
z = 3;
}
int x, y, z;
};
struct B
{
B()
{
a = 1.5f;
b = 2.5f;
c = 3.5f;
}
float a, b, c;
};
}
clcpp_impl_class(TestClassImpl::A)
clcpp_impl_class(TestClassImpl::B)
void TestConstructorDestructor(clcpp::Database& db)
{
const clcpp::Class* ca = clcpp::GetType<TestClassImpl::A>()->AsClass();
const clcpp::Class* cb = clcpp::GetType<TestClassImpl::B>()->AsClass();
TestClassImpl::A* a = (TestClassImpl::A*)new char[sizeof(TestClassImpl::A)];
TestClassImpl::B* b = (TestClassImpl::B*)new char[sizeof(TestClassImpl::B)];
CallFunction(ca->constructor, a);
CallFunction(cb->constructor, b);
CallFunction(ca->destructor, a);
CallFunction(cb->destructor, b);
delete [] (char*) a;
delete [] (char*) b;
}
https://github.com/Celtoys/clReflect/blob/master/src/clReflectTest/TestClassImpl.cpp
−1
/**
* @throw std::system_error
*/
auto udp_echo_service(int64_t sd) -> no_return_t {
sockaddr_in remote{};
io_work_t work{};
io_buffer_t buf{}; // memory view to the 'storage'
io_buffer_reserved_t storage{}; // each coroutine frame contains buffer
while (true) {
// packet length(read)
auto len = co_await recv_from(sd, remote, buf = storage, work);
// instead of length check, see the error from the 'io_work_t' object
if (work.error())
goto OnError;
buf = {storage.data(), static_cast<size_t>(len)};
len = co_await send_to(sd, remote, buf, work);
if (work.error())
goto OnError;
assert(len == buf.size_bytes());
}
co_return;
OnError:
// expect ERROR_OPERATION_ABORTED (the socket is closed in this case)
const auto ec = work.error();
const auto emsg = system_category().message(ec);
fputs(emsg.c_str(), stderr);
}
https://github.com/luncliff/coroutine/blob/main/test/net_socket_udp_echo.cpp
0
bool addPlayer(const Addr & addr,
Poco::Nullable<const std::string> serverAddr,
Poco::Nullable<bool> isKeyReceived,
Poco::Nullable<std::string> key,
Poco::Nullable<time_t> lastHashCheck,
Poco::Nullable<std::string> digest)
{
bool isPlaying = !serverAddr.isNull();
bool isKeyReceivedReal = isKeyReceived.isNull();
time_t lastHashCheckReal = lastHashCheck.isNull() ? time(0) : lastHashCheck.value();
std::string keyReal(key.isNull() ? "" : key.value());
std::string playerAddr = addr.getHost();
std::string serverAddrReal(serverAddr.isNull() ? "" : serverAddr.value());
std::string digestReal = digest.isNull() ? "" : digest.value();
Statement insert(*playersSession);
insert << "INSERT INTO Players VALUES(?, ?, ?, ?, ?, ?, ?)",
use(playerAddr), // Addr
use(serverAddrReal), // Server
use(isPlaying),
use(isKeyReceivedReal),
use(keyReal), // Key
use(lastHashCheckReal),
use(digestReal);
insert.execute();
return true;
}
0
#define MIRAGE_COFU(T, name, ...) \
inline struct _##name##cofu { T instance{ __VA_ARGS__ }; T& operator()(void) { return instance; }; \
static bool destructed; ~_##name##cofu(void) { destructed = true; } static bool isDestructed(void) \
{ return destructed; } } name; inline bool _##name##cofu::destructed = false
кофу
−1
#include <stdio.h>
int main() {
char* pituh;
puts(pituh);
pituh = "kokoko";
return 0;
}
Угадайте что выведет код?
ISO и прочим скилловикам просьба воздержаться.
https://ideone.com/sYrqiB
0
template<int I> struct Tag {};
template<int I>
struct StaticMock : mirage::ecs::Component<StaticMock<I>>
{
static bool initializeds;
void initialize(void)
{
initializeds = true;
}
};
template<>
struct StaticMock<2> : mirage::ecs::Component<StaticMock<2>>
{
static bool initializeds;
void initialize(Tag<2>&)
{
initializeds = true;
}
};
template<int I>
inline bool StaticMock<I>::initializeds = false;
inline bool StaticMock<2>::initializeds = false;
using Tag1 = Tag<1>;
using StaticMock1 = StaticMock<1>;
using Tag2 = Tag<2>;
using StaticMock2 = StaticMock<2>;
MIRAGE_CREATE_ON_STARTUP(StaticMock<0>, staticOnStartMock);
MIRAGE_CREATE_ON_EVENT(Tag1, StaticMock1);
MIRAGE_CREATE_WITH_EVENT(Tag2, StaticMock2);
TEST(Ecs, StaticOnStart)
{
EXPECT_EQ(StaticMock<0>::initializeds, true);
}
TEST(Ecs, StaticOnEvent)
{
EXPECT_NE(StaticMock1::initializeds, true);
mirage::event::enqueueEvent<Tag1>();
std::this_thread::sleep_for(std::chrono::milliseconds(
mirage::ecs::processing::EventDispatcherProcessing::updatePeriod * 2));
EXPECT_EQ(StaticMock1::initializeds, true);
}
TEST(Ecs, StaticWithEvent)
{
EXPECT_NE(StaticMock2::initializeds, true);
mirage::event::enqueueEvent<Tag2>();
std::this_thread::sleep_for(std::chrono::milliseconds(
mirage::ecs::processing::EventDispatcherProcessing::updatePeriod * 2));
EXPECT_EQ(StaticMock2::initializeds, true);
}
0
try
{
}
catch(...) { /*um, nice weather!*/}
0
#include <iostream>
int main() {
const char* pituh = {};
std::cout << pituh;
}
Нахуя?