- 1
- 2
- 3
int i = 42;
foo(i); //не компилируется
foo(static_cast<int>(i)); //компилируется
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
int i = 42;
foo(i); //не компилируется
foo(static_cast<int>(i)); //компилируется
0
// -------------------------------------------
// 2.2. binary calls
// -------------------------------------------
/*
combination table:
+- | c a n
---|-------
c | C A N
a | A A N
n | N N N
* | c a n
---|-------
c | C A N
a | A N N
n | N N N
/ | c a n
---|-------
c | C N N
a | A N N
n | N N N
argument:
c : constant, as scalar, point, tensor, ect
l : affine homogeneous expr argument: as field, field_indirect or field_expr_node::is_affine_homogeneous
n : function, functor or ! field_expr_node::is_affine_homogeneous
result:
C : constant : this combination is not implemented here
A,N : are implemented here
rules:
at least one of the two args is not of type "c"
when c: c value is embeded in bind_first or bind_second
and the operation reduces to an unary one
when a: if it is a field_convertible, it should be wrapped
in field_expr_v2_nonlinear_terminal_field
when c: no wrapper is need
implementation:
The a and n cases are grouped, thanks to the wrapper_traits
and it remains to cases :
1) both args are field_expr_v2_nonlinear or a function
2) one arg is a field_expr_v2_nonlinear or a function and the second argument is a constant
*/
#define _RHEOLEF_make_field_expr_v2_nonlinear_binary(FUNCTION,FUNCTOR) \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_field_expr_v2_nonlinear_arg<Expr1>::value \
&& details::is_field_expr_v2_nonlinear_arg<Expr2>::value \
&& ! details::is_field_expr_v2_constant <Expr1>::value \
&& ! details::is_field_expr_v2_constant <Expr2>::value \
,details::field_expr_v2_nonlinear_node_binary< \
FUNCTOR \
,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type \
,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type wrap1_t; \
typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type wrap2_t; \
return details::field_expr_v2_nonlinear_node_binary <FUNCTOR,wrap1_t,wrap2_t> \
(FUNCTOR(), wrap1_t(expr1), wrap2_t(expr2)); \
} \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_field_expr_v2_constant <Expr1>::value \
&& details::is_field_expr_v2_nonlinear_arg<Expr2>::value \
&& ! details::is_field_expr_v2_constant <Expr2>::value \
,details::field_expr_v2_nonlinear_node_unary< \
details::binder_first< \
FUNCTOR \
,typename details::field_promote_first_argument< \
Expr1
0
#include <iostream>
#include <ctime>
using namespace std;
#define SIZE 200000000
struct StackRazrivator {
int data[SIZE];
};
void razorvi() {
cout << "nachinau razrivat\n";
StackRazrivator r;
}
void razrivator() {
cout << "razrivator\n";
razorvi();
}
int main() {
cout << "start" << endl;
razrivator();
return 0;
}
Что выведет программа, если скомпилировать без оптимизаций и почему?
https://godbolt.org/z/75Yzer
−1
void setAreaPreScale(double scale)
{
if(scale == 1)
setFrameSize(initialFrameSize.first, initialFrameSize.second);
else
{
double widthPart = (1 - initialFrameSize.first) * (1 - scale);
double heightPart = (1 - initialFrameSize.second) * (1 - scale);
setFrameSize(initialFrameSize.first + widthPart, initialFrameSize.second + heightPart);
}
}
требуется сделать отложенное масштабирование картинки, сначала рисуется (и скейлится методом setAreaPreScale) рамка с областью, в которую будет замасштабировано, затем отдельной кнопкой будет масштабироваться. в методе происходит рассчёт размера в пикселях рамки прескейла по параметру scale (отношение будущего масштаба к текущему). initialFrameSize на самом деле maxFrameSize, но авторский код сохранён
0
// foo.h
namespace Xru {
struct Foo {
Foo();
};
}
// foo1.cpp
#include <foo.h>
using namespace Xru;
Foo::Foo() {}
// foo2.cpp
#include <foo.h>
namespace Xru {
Foo::Foo() {}
}
Вы пишите как 1 или 2?
До меня другой коллега доёбуецца, что нужно как 2.
0
struct Foo { Foo(int, int); };
struct Bar { explicit Bar(int, int); };
Foo f1(1, 1); // ok
Foo f2 {1, 1}; // ok
Foo f3 = {1, 1}; // ok
Bar b1(1, 1); // ok
Bar b2 {1, 1}; // ok
Bar b3 = {1, 1}; // NOT OKAY
А вы пишите explicit у коньструкторов? До меня коллега доёбуецца, что я не пишу.
0
// https://github.com/google/ruy/blob/2887692065c38ef6617f423feafc6b69dd0a0681/ruy/pack_avx2_fma.cc#L66
inline void Pack8bitColMajorForAvx2Packer(
const std::int8_t* src_ptr, std::int8_t input_xor,
const std::int8_t* zerobuf, int src_stride, int remaining_src_cols,
int src_rows, std::int8_t* packed_ptr, std::int32_t* sums_ptr,
std::int8_t* trailing_buf) {
using Layout = PackImpl8bitAvx2::Layout;
RUY_DCHECK_EQ(Layout::kCols, 8);
RUY_DCHECK_EQ(Layout::kRows, 4);
// Each Layout::Rows is 4 contiguous input, contiguous packed elements.
// We process 8 of these chunks at a time, padding short input chunks.
constexpr int kNumRowChunks = 8;
constexpr int kNumChunkedSrcRows = kNumRowChunks * Layout::kRows;
const std::int8_t* src_ptr0 = src_ptr;
const std::int8_t* src_ptr1 = src_ptr0 + src_stride;
const std::int8_t* src_ptr2 = src_ptr1 + src_stride;
const std::int8_t* src_ptr3 = src_ptr2 + src_stride;
const std::int8_t* src_ptr4 = src_ptr3 + src_stride;
const std::int8_t* src_ptr5 = src_ptr4 + src_stride;
const std::int8_t* src_ptr6 = src_ptr5 + src_stride;
const std::int8_t* src_ptr7 = src_ptr6 + src_stride;
std::int64_t src_inc0 = kNumChunkedSrcRows;
std::int64_t src_inc1 = kNumChunkedSrcRows;
std::int64_t src_inc2 = kNumChunkedSrcRows;
std::int64_t src_inc3 = kNumChunkedSrcRows;
std::int64_t src_inc4 = kNumChunkedSrcRows;
std::int64_t src_inc5 = kNumChunkedSrcRows;
std::int64_t src_inc6 = kNumChunkedSrcRows;
std::int64_t src_inc7 = kNumChunkedSrcRows;
// Handle cases where source does not have Layout::kCols (8) columns.
if (remaining_src_cols < 8) {
if (remaining_src_cols <= 0) {
src_ptr0 = zerobuf;
src_inc0 = 0;
}
if (remaining_src_cols <= 1) {
src_ptr1 = zerobuf;
src_inc1 = 0;
}
if (remaining_src_cols <= 2) {
src_ptr2 = zerobuf;
src_inc2 = 0;
}
if (remaining_src_cols <= 3) {
src_ptr3 = zerobuf;
src_inc3 = 0;
}
if (remaining_src_cols <= 4) {
src_ptr4 = zerobuf;
src_inc4 = 0;
}
if (remaining_src_cols <= 5) {
src_ptr5 = zerobuf;
src_inc5 = 0;
}
if (remaining_src_cols <= 6) {
src_ptr6 = zerobuf;
src_inc6 = 0;
}
src_ptr7 = zerobuf;
src_inc7 = 0;
}
const std::int8_t zero_point = zerobuf[0];
if (sums_ptr) {
// i: Layout::kCols.
for (int i = 0; i < 8; ++i) {
sums_ptr[i] = 0;
}
}
std::int32_t sums_adjustment = 0;
const __m256i ones_16bit = _mm256_set1_epi16(1);
__m256i sums_4x2_32bit_lo = _mm256_set1_epi32(0);
__m256i sums_4x2_32bit_hi = _mm256_set1_epi32(0);
// The overall packing effectively pads the source rows to
// (src_rows + 63) & ~63. The iteration over k may skip when m=1, and then we
// only pack for (src_rows + 31) & ~31. When there is an incomplete
// destination block, this is stored into trailing_buf instead of packed_ptr.
for (int k = 0; k < src_rows; k += kNumChunkedSrcRows) {
// Available source rows.
// If this is less than 0 (for m=1), we skip, having filled trailing
// buffer for m=0. Also, if source rows is zero on m=1, then we filled
// exactly to the end of the column in the packed buffer.
const int available_src_rows = src_rows - k;
// Effectively,
// available rows = std::max(0, std::min(8, src_rows - k));
// treat each case separately.
if (available_src_rows >= kNumChunkedSrcRows) {
if (sums_ptr) {
__m256i t0, t1, t2, t3, t4, t5, t6, t7;
__m256i r0, r1, r2, r3, r4, r5, r6, r7;
const __m256i input_xor_v = _mm256_set1_epi8(input_xor);
t0 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr0));
t4 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr4));
t1 = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src_ptr1));
Интересно, они это вручную всё писали, или какой-то хуйней генерировали?
0
// https://github.com/WebKit/WebKit/blob/31b77296cf6d85c40313812d9f65a003cf41f440/Source/WebCore/page/Quirks.cpp#L330
bool Quirks::isGoogleMaps() const
{
auto& url = m_document->topDocument().url();
return topPrivatelyControlledDomain(url.host().toString()).startsWith("google.") && url.path().startsWithIgnoringASCIICase("/maps/");
}
bool Quirks::shouldDispatchSimulatedMouseEvents() const
{
if (RuntimeEnabledFeatures::sharedFeatures().mouseEventsSimulationEnabled())
return true;
if (!needsQuirks())
return false;
auto doShouldDispatchChecks = [this] () -> bool {
auto* loader = m_document->loader();
if (!loader || loader->simulatedMouseEventsDispatchPolicy() != SimulatedMouseEventsDispatchPolicy::Allow)
return false;
if (isAmazon())
return true;
if (isGoogleMaps())
return true;
auto& url = m_document->topDocument().url();
auto host = url.host().convertToASCIILowercase();
if (host == "wix.com" || host.endsWith(".wix.com")) {
// Disable simulated mouse dispatching for template selection.
return !url.path().startsWithIgnoringASCIICase("/website/templates/");
}
if ((host == "desmos.com" || host.endsWith(".desmos.com")) && url.path().startsWithIgnoringASCIICase("/calculator/"))
return true;
if (host == "figma.com" || host.endsWith(".figma.com"))
return true;
if (host == "trello.com" || host.endsWith(".trello.com"))
return true;
if (host == "airtable.com" || host.endsWith(".airtable.com"))
return true;
if (host == "msn.com" || host.endsWith(".msn.com"))
return true;
if (host == "flipkart.com" || host.endsWith(".flipkart.com"))
return true;
if (host == "iqiyi.com" || host.endsWith(".iqiyi.com"))
return true;
if (host == "trailers.apple.com")
return true;
if (host == "soundcloud.com")
return true;
if (host == "naver.com")
return true;
if (host == "nba.com" || host.endsWith(".nba.com"))
return true;
if (host.endsWith(".naver.com")) {
// Disable the quirk for tv.naver.com subdomain to be able to simulate hover on videos.
if (host == "tv.naver.com")
return false;
// Disable the quirk for mail.naver.com subdomain to be able to tap on mail subjects.
if (host == "mail.naver.com")
return false;
// Disable the quirk on the mobile site.
// FIXME: Maybe this quirk should be disabled for "m." subdomains on all sites? These are generally mobile sites that don't need mouse events.
if (host == "m.naver.com")
return false;
return true;
}
return false;
};
if (!m_shouldDispatchSimulatedMouseEventsQuirk)
m_shouldDispatchSimulatedMouseEventsQuirk = doShouldDispatchChecks();
return *m_shouldDispatchSimulatedMouseEventsQuirk;
}
Дааа блядь, давайте в движке браузера захардкодим какие-то говнодомены, что типа вот для них какая-то там блядь симуляция событий мыши работала каким-то таким образом. Охуенно!
+1
// https://quuxplusone.github.io/blog/2021/01/13/conversion-operator-lookup/
struct A {
using T = T1;
using U = U1;
operator U1 T1::*();
operator U1 T2::*();
operator U2 T1::*();
operator U2 T2::*();
};
inline auto which(U1 T1::*) { return "gcc"; }
inline auto which(U1 T2::*) { return "icc"; }
inline auto which(U2 T1::*) { return "msvc"; }
inline auto which(U2 T2::*) { return "clang"; }
int main() {
A a;
using T = T2;
using U = U2;
puts(which(a.operator U T::*()));
}
> As of this writing (but perhaps not for very much longer!) the four mainstream compilers on Godbolt Compiler Explorer give four different answers for this simple C++ program:
> According to the current draft standard, it sounds like the conforming answer is “they should both be looked up in the scope of A”; i.e., GCC’s answer is correct and the others are wrong in three different ways.
Какой багор )))
+1
void testToken(const char *value, size_t tokenExpected)
{
antlr4::ANTLRInputStream input(value);
typescript::TypeScriptLexerANTLR lexer(&input);
auto tokens = lexer.getAllTokens();
printTokens(lexer, tokens);
auto token = tokens.front().get();
std::ostringstream stringStream;
stringStream << "Expecting: [" << lexer.getTokenNames()[tokenExpected] << "] \"" << value << "\" but get: [" << lexer.getTokenNames()[token->getType()] << "] \"" << token->getText() << "\".";
auto msg = stringStream.str();
ASSERT_EQUAL_MSG(token->getType(), tokenExpected, msg);
ASSERT_THROW_MSG(token->getText().compare(value) == 0, msg);
}
void testOctalIntegerLiteral()
{
testToken("01", l::OctalIntegerLiteral);
}
Мой расказ о том как жизни было нехрен делать и я начал писать копилятор для TypeScript. как это "пинание х..я" кончиться я не знаю. но вот начал с простого. собрал минимум для разработки это LLVM и ANTLR4. И уже написал свой первый (ну не совсем) lexer.
вот тут можно посмотреть на убогость говнокода.
https://github.com/ASDAlexander77/TypeScriptCompiler