C++ (GCC -O0)
#include <cstdlib>
#include <cstdint>
#include <iostream>
void *aCaller = NULL;
bool a()
{
aCaller = __builtin_extract_return_addr(__builtin_return_address(0));
return true;
}
bool b()
{
void *bCaller = __builtin_extract_return_addr(__builtin_return_address(0));
return abs(((char*)bCaller - (char*)aCaller)) > 9;
}
int main()
{
if (a()) std::cout << "a is true" << std::endl;
if (b()) std::cout << "b is true" << std::endl;
if (a() && b()) std::cout << "a && b is true" << std::endl;
return 0;
}
As of submission, this is the only solution so far that doesn't redefineuse a different/redefined AND or use operator precedence tricks, but rather uses a straight-up logical AND.
The trick is that a() and b() are functions, the latter of which returns false if it's been called very close after a() was last called. As such it's probably not very portable, and if it is, at the very least the threshold of 9 bytes may need to be modified to work on different architectures.