#define — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #define, aggregated by home.social.
-
CW: Not screen reader friendly: raw git patch inside
@hyc Hey, not sure where to ask about this, I have problems where LMDB doesn't build on MingW64-w64 due to what I suspect is a dumb NT type mismatch, a cast to (size_t*) fixed it in a pinch but I am not confident it is the ideal solution (I am no NT user)
Here is a small patch that just points where the problem occurs, I will leave it entirely to your judgement
--------------------------
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 0cc1bbb..8159a2f 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -6949,7 +6949,7 @@ mdb_rpage_get(MDB_txn *txn, pgno_t pg0, int numpgs, MDB_page **ret, MDB_page **e
#define MAP(rc,env,addr,len,off) \
addr = NULL; \
rc = NtMapViewOfSection(env->me_fmh, GetCurrentProcess(), (void **)&addr, 0, \
- len, &off, &len, ViewUnmap, (env->me_flags & MDB_RDONLY) ? 0 : MEM_RESERVE, PAGE_READONLY); \
+ len, &off, /* Some cast required */&len, ViewUnmap, (env->me_flags & MDB_RDONLY) ? 0 : MEM_RESERVE, PAGE_READONLY); \
if (rc) rc = mdb_nt2win32(rc)
#else
off_t off; -
CW: Not screen reader friendly: raw git patch inside
@hyc Hey, not sure where to ask about this, I have problems where LMDB doesn't build on MingW64-w64 due to what I suspect is a dumb NT type mismatch, a cast to (size_t*) fixed it in a pinch but I am not confident it is the ideal solution (I am no NT user)
Here is a small patch that just points where the problem occurs, I will leave it entirely to your judgement
--------------------------
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 0cc1bbb..8159a2f 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -6949,7 +6949,7 @@ mdb_rpage_get(MDB_txn *txn, pgno_t pg0, int numpgs, MDB_page **ret, MDB_page **e
#define MAP(rc,env,addr,len,off) \
addr = NULL; \
rc = NtMapViewOfSection(env->me_fmh, GetCurrentProcess(), (void **)&addr, 0, \
- len, &off, &len, ViewUnmap, (env->me_flags & MDB_RDONLY) ? 0 : MEM_RESERVE, PAGE_READONLY); \
+ len, &off, /* Some cast required */&len, ViewUnmap, (env->me_flags & MDB_RDONLY) ? 0 : MEM_RESERVE, PAGE_READONLY); \
if (rc) rc = mdb_nt2win32(rc)
#else
off_t off; -
-
Magie d’Ækeynox, on dispose du même niveau d’émulation pour #QwertyLafayette. Il suffit d’ajuster les options dans
settings.h:#define KB_LAYOUT_AZERTY
#define KB_EMULATION_QWERTY_LAFAYETTE
#define ENABLE_CP1252_ALT_CODESL’émulation sur Azerty « fait le job », mais ne supporte pas les caractères accentués en CapsLock. L’émulation sur Qwerty-intl ne souffre pas de cette limitation (Ergol ou Lafayette) :
#define KB_LAYOUT_QWERTY_INTL
#define KB_EMULATION_QWERTY_LAFAYETTE
#define ENABLE_CP1252_ALT_CODES -
Magie d’Ækeynox, on dispose du même niveau d’émulation pour #QwertyLafayette. Il suffit d’ajuster les options dans
settings.h:#define KB_LAYOUT_AZERTY
#define KB_EMULATION_QWERTY_LAFAYETTE
#define ENABLE_CP1252_ALT_CODESL’émulation sur Azerty « fait le job », mais ne supporte pas les caractères accentués en CapsLock. L’émulation sur Qwerty-intl ne souffre pas de cette limitation (Ergol ou Lafayette) :
#define KB_LAYOUT_QWERTY_INTL
#define KB_EMULATION_QWERTY_LAFAYETTE
#define ENABLE_CP1252_ALT_CODES -
L’émulation #Ergol dans #Ækeynox a atteint un niveau très satisfaisant, grâce à @ashiel qui vient d’implémenter de quoi faire des espaces insécables ! Je l’utilise en ce moment même pour écrire ce post.
https://github.com/OneDeadKey/zmk-config-aekeynox/pull/90Pour l’instant c’est spécifique à un hôte Windows en Azerty. Il faut décommenter ces lignes-ci dans le fichier
settings.h:#define KB_LAYOUT_AZERTY
#define KB_EMULATION_ERGOL
#define ENABLE_CP1252_ALT_CODEShttps://github.com/OneDeadKey/zmk-config-aekeynox/blob/main/include/aekeynox/settings.h
L’opération est accessible à celles et ceux qui connaissent un peu GitHub : tirer une branche, modifier
settings.h, attendre le build dans les « Actions »… Pour les autres, on tâchera de proposer des firmwares en téléchargement à la rentrée.Cette émulation n’est pas réservée au #Quacken, elle fonctionne pour tous les claviers supportés par Ækeynox : Ferris, Totem, Corne, Glove80, Go60…
-
L’émulation #Ergol dans #Ækeynox a atteint un niveau très satisfaisant, grâce à @ashiel qui vient d’implémenter de quoi faire des espaces insécables ! Je l’utilise en ce moment même pour écrire ce post.
https://github.com/OneDeadKey/zmk-config-aekeynox/pull/90Pour l’instant c’est spécifique à un hôte Windows en Azerty. Il faut décommenter ces lignes-ci dans le fichier
settings.h:#define KB_LAYOUT_AZERTY
#define KB_EMULATION_ERGOL
#define ENABLE_CP1252_ALT_CODEShttps://github.com/OneDeadKey/zmk-config-aekeynox/blob/main/include/aekeynox/settings.h
L’opération est accessible à celles et ceux qui connaissent un peu GitHub : tirer une branche, modifier
settings.h, attendre le build dans les « Actions »… Pour les autres, on tâchera de proposer des firmwares en téléchargement à la rentrée.Cette émulation n’est pas réservée au #Quacken, elle fonctionne pour tous les claviers supportés par Ækeynox : Ferris, Totem, Corne, Glove80, Go60…
-
The next presenter described how their compiler accepts a dialect of HLSL that allows you to annotate your global resources with vulkan binding information.
They recommended an approach where you put both HLSL semantics and these [[vk::foo()]] things in your source code, in order to be able to use the same source on both DirectX and Vulkan. They said that, when you run your HLSL through fxc, you can #define the vk::foo() things to nothing.
5/7
-
The next presenter described how their compiler accepts a dialect of HLSL that allows you to annotate your global resources with vulkan binding information.
They recommended an approach where you put both HLSL semantics and these [[vk::foo()]] things in your source code, in order to be able to use the same source on both DirectX and Vulkan. They said that, when you run your HLSL through fxc, you can #define the vk::foo() things to nothing.
5/7
-
@gvwilson somewhere in the programming code...
enum sexbotmodes = {
SEXBOT_MODE_REAL_TEACHER,
SEXBOT_MODE_SEXY_TEACHER,
SEXBOT_MODE_CREEPY_TEACHER,
SEXBOT_MODE_HOT_FOR_AIBROS,
SEXBOT_MODE_HOT_FOR_SEXBOTS
};#if defined(TEACHER) && defined(REAL_TEACHER)
#define SEXBOT_MODE_DEFAULT SEXBOT_MODE_REAL_TEACHER
#else
#define SEXBOT_MODE_DEFAULT SEXBOT_MODE_HOT_FOR_AIBROS
#endifbool sexbot_mode = SEXBOT_MODE_DEFAULT;
-
@gvwilson somewhere in the programming code...
enum sexbotmodes = {
SEXBOT_MODE_REAL_TEACHER,
SEXBOT_MODE_SEXY_TEACHER,
SEXBOT_MODE_CREEPY_TEACHER,
SEXBOT_MODE_HOT_FOR_AIBROS,
SEXBOT_MODE_HOT_FOR_SEXBOTS
};#if defined(TEACHER) && defined(REAL_TEACHER)
#define SEXBOT_MODE_DEFAULT SEXBOT_MODE_REAL_TEACHER
#else
#define SEXBOT_MODE_DEFAULT SEXBOT_MODE_HOT_FOR_AIBROS
#endifbool sexbot_mode = SEXBOT_MODE_DEFAULT;
-
-
-
I think custom fmt are quintessential. Added support, diff:
```diff
diff --git a/main.c b/main.c
index 68154cd..8eabe56 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,14 @@
#define STR_SIZE 64
// Waits for second transition and prints date
-int main() {
+int main(int argc, char *argv[]) {
+ // Default fmt
+ char *fmt = "%Y-%m-%d %X";
+ // Use custom fmt if provided
+ if (argc > 1) {
+ fmt = argv[1];
+ }
+
int tfd = timerfd_create(CLOCK_REALTIME, 0);
struct itimerspec exp = {0};
time_t cur = time(NULL);
@@ -41,7 +48,7 @@ int main() {
// Add them. long += ulong should be fine?
cur += exps;
localtime_r(&cur, &bt);
- strftime(str, STR_SIZE, "%Y-%m-%d %X", &bt);
+ strftime(str, STR_SIZE, fmt , &bt);
puts(str);
fflush(stdout);
}
``` -
I think custom fmt are quintessential. Added support, diff:
```diff
diff --git a/main.c b/main.c
index 68154cd..8eabe56 100644
--- a/main.c
+++ b/main.c
@@ -22,7 +22,14 @@
#define STR_SIZE 64
// Waits for second transition and prints date
-int main() {
+int main(int argc, char *argv[]) {
+ // Default fmt
+ char *fmt = "%Y-%m-%d %X";
+ // Use custom fmt if provided
+ if (argc > 1) {
+ fmt = argv[1];
+ }
+
int tfd = timerfd_create(CLOCK_REALTIME, 0);
struct itimerspec exp = {0};
time_t cur = time(NULL);
@@ -41,7 +48,7 @@ int main() {
// Add them. long += ulong should be fine?
cur += exps;
localtime_r(&cur, &bt);
- strftime(str, STR_SIZE, "%Y-%m-%d %X", &bt);
+ strftime(str, STR_SIZE, fmt , &bt);
puts(str);
fflush(stdout);
}
``` -
-
-
@YoSoyFreeman that's how I do it, II reserve casing for functions, definitions, classes, namespaces, etc. It helps to visually distinguish at a glance. I use underscore separators if needed for variable names.
specifically
ALL CAPS + snake case: macro/definitions/namespaces (eg. #define MAX_PRECISION 0.01)
all lower + snake case: variables, primitive typedefs (eg. fs::path default_config_path)
PascalCase: classes, structures, enums, functions (eg. class ConfigFile)
-
@YoSoyFreeman that's how I do it, II reserve casing for functions, definitions, classes, namespaces, etc. It helps to visually distinguish at a glance. I use underscore separators if needed for variable names.
specifically
ALL CAPS + snake case: macro/definitions/namespaces (eg. #define MAX_PRECISION 0.01)
all lower + snake case: variables, primitive typedefs (eg. fs::path default_config_path)
PascalCase: classes, structures, enums, functions (eg. class ConfigFile)
-
-
-
/usr/bin/cat
is fucking complicated.
(yeah, okay, it's not like I was actually **expecting** to see what the K&R books would lead you to believe is there:
#include <unistd.h>
#include <stdio.h>
#define BLEN 256
int main() {
char buffer[BLEN], *b; int cr, cw;
goto read;
for (;;) {
while (0 == (cw = write(1, b, cr)))
sleep(1);
if (cw < 0)
return (perror("write error"), 1);
if ((b+=cw, cr-=cw) > 0) continue;
read:
if (0 >= (cr = read(0, buffer, BLEN)))
return (0 == cr /* EOF? */
? 0 : perror("read error"), 1);
b = buffer;
}
}but it still amazes me just how much longer the actual version is (and how many bells and whistles have been added over the years).
-
/usr/bin/cat
is fucking complicated.
(yeah, okay, it's not like I was actually **expecting** to see what the K&R books would lead you to believe is there:
#include <unistd.h>
#include <stdio.h>
#define BLEN 256
int main() {
char buffer[BLEN], *b; int cr, cw;
goto read;
for (;;) {
while (0 == (cw = write(1, b, cr)))
sleep(1);
if (cw < 0)
return (perror("write error"), 1);
if ((b+=cw, cr-=cw) > 0) continue;
read:
if (0 >= (cr = read(0, buffer, BLEN)))
return (0 == cr /* EOF? */
? 0 : perror("read error"), 1);
b = buffer;
}
}but it still amazes me just how much longer the actual version is (and how many bells and whistles have been added over the years).
-
```c
#pragma region Maps.
static inline void mapTextures() {
#define M(p_texture, p_path) g_texturePaths[p_texture] = p_path; g_texturePathLengths[p_texture] = sizeof(p_path)M(TEXTURE_MISSING, "missing.png");
M(TEXTURE_BLACK, "black.png");
M(TEXTURE_WHITE, "white.png");
M(TEXTURE_GRID, "grid.png");#undef M
}
``` -
PS If you're interested in what "codegen" I was doing in "My C Code", here it is:
```h
#define T(x) TEXTURE_ ## x
enum TextureName {T(MISSING),
T(BLACK),
T(WHITE),
T(GRID),T(TOTAL)
};
#undef Tvoid loadTextures();
extern pixel_t *g_textureData[TEXTURE_TOTAL];
extern char const *g_texturePaths[TEXTURE_TOTAL];
extern size_t g_texturePathLengths[TEXTURE_TOTAL];
extern struct SmlVec2 g_textureDims[TEXTURE_TOTAL];
``` -
Took way, way too long but this code now works as-intended in GCC.
#include <stdio.h>
#define bar(x) _Generic(x, \
int v: v, \
const double: (int)2.0,\
const int v: v * 2,\
struct foo v: v.name \
)
struct foo { char* name; };
extern int x;
int fn(void) {
return x += 1;
}
double fnd(void) {
return (double)(x += 1);
}
int main() {
struct foo f = { "test" };
int v1 = _Generic(3, int v [[maybe_unused]]: 3);
printf("%d (expected: 3)\n", v1);
int v2 = _Generic(x, int v [[maybe_unused]]: v, double v: (int)v);
printf("%d (expected: 20)\n", v2);
bar(f) = "something";
printf("%s (expected: something)\n", f.name);
printf("(part 1, x before = %d)\n", x);
int v3 = _Generic(fn(), int v: 0, double v: (int)v);
printf("%d (expected: 0)\n", v3);
printf("(part 1, x after = %d)\n", x);
printf("(part 2, x before = %d)\n", x);
int v4 = _Generic(fn(), int v: v * v, double v: (int)v);
printf("%d (expected: 484)\n", v4);
printf("(part 2, x after = %d)\n", x);
printf("(part 3, x before = %d)\n", x);
int v5 = _Generic(fnd(), int v: v * v, double: 3.0);
printf("%d (expected: 3)\n", v5);
printf("(part 3, x after = %d)\n", x);
const int xc = 20;
int v6 = _Generic(xc,
int v: v * v,
double: 3.0
);
printf("%d (expected: 400)\n", v6);
return 0;
}
int x = 20; -
#define avoid [[deprecated]] void
avoid func() { ... }
-
#define avoid [[deprecated]] void
avoid func() { ... }
-
Robot Dog in Browser
You’ve doubtlessly seen the current crop of robot dogs and, if you are like us, thought about getting one to play with. The problem is that the cheap ones are toys, and the serious ones cost serious money. But now you can experiment with a mid-range cost one for free in your browser. The sponsor will be happy to sell you a robot in kit or assembled form, although it is the OpenCat robot (we’ve covered it before), so you could simply build a real one yourself if you wanted to.
The code is all in a Web-based IDE, and the main file is deceptively simple. However, the real work is in
read_serial(in the src/moduleManager.h file, for some reason) andreactionin the aptly-named src/reaction.h file. If you just want to play, you can use the buttons in the simulator or enter serial commands (documented elsewhere). For example,ksitwill make the dog sit down.You can change as much code as you like. You might consider starting simple and just sending commands programmatically, but you can dive as deep as you like. Press compile up at the top right, and it will load and run your code in the virtual robot. If you run it off the desk (of course, we did), you can reset and try again.
Here’s a quick example to get you started:
//***********************
#define BITTLE // Petoi 9 DOF robot dog: 1 on head + 8 on leg#define BiBoard_V1_0
//***********************#include "src/OpenCat.h"
void setup() {
Serial.begin(115200); // USB serial
Serial.setTimeout(SERIAL_TIMEOUT);while (Serial.available() && Serial.read())
; // empty bufferSerial.println("Hello Hackaday!");
initRobot();
}unsigned int loopct=0;
unsigned int phase=0;#define cmdtokenEOF 0xFFFF
// commands (token + argument)
char *cmd[] =
{
"sit", // good boy
"up", // stand up
"bf", // back flip
"ff", // forward flip
"EOF" // string doesn't matter here
};unsigned int cmdtoken[] = {
T_SKILL,
T_SKILL,
T_SKILL,
T_SKILL,
cmdtokenEOF
};#define LOOPDELAY 1000 // number of loops between actions
void loop() {
// This code runs repeatedly
// Put any change here if you want to change behaviors
if (loopct % 1000 == 0 )
{
loopct=0;
if (cmdtoken[phase]==cmdtokenEOF) phase=0;
strcpy(newCmd,cmd[phase]);
token=cmdtoken[phase++];
newCmdIdx=1;
}
loopct++;reaction();
}The robot is better than the cheap toys, but it still lacks many sensors. You can add on a few simple sensors that appear to mount in the dog’s mouth, or you can replace its head with an arm if you opt for beefy enough servos.
Of course, we’ve seen plenty of robot dogs. We want one, but we don’t know what we’d do with it. Any ideas?
-
Robot Dog in Browser
You’ve doubtlessly seen the current crop of robot dogs and, if you are like us, thought about getting one to play with. The problem is that the cheap ones are toys, and the serious ones cost serious money. But now you can experiment with a mid-range cost one for free in your browser. The sponsor will be happy to sell you a robot in kit or assembled form, although it is the OpenCat robot (we’ve covered it before), so you could simply build a real one yourself if you wanted to.
The code is all in a Web-based IDE, and the main file is deceptively simple. However, the real work is in
read_serial(in the src/moduleManager.h file, for some reason) andreactionin the aptly-named src/reaction.h file. If you just want to play, you can use the buttons in the simulator or enter serial commands (documented elsewhere). For example,ksitwill make the dog sit down.You can change as much code as you like. You might consider starting simple and just sending commands programmatically, but you can dive as deep as you like. Press compile up at the top right, and it will load and run your code in the virtual robot. If you run it off the desk (of course, we did), you can reset and try again.
Here’s a quick example to get you started:
//***********************
#define BITTLE // Petoi 9 DOF robot dog: 1 on head + 8 on leg#define BiBoard_V1_0
//***********************#include "src/OpenCat.h"
void setup() {
Serial.begin(115200); // USB serial
Serial.setTimeout(SERIAL_TIMEOUT);while (Serial.available() && Serial.read())
; // empty bufferSerial.println("Hello Hackaday!");
initRobot();
}unsigned int loopct=0;
unsigned int phase=0;#define cmdtokenEOF 0xFFFF
// commands (token + argument)
char *cmd[] =
{
"sit", // good boy
"up", // stand up
"bf", // back flip
"ff", // forward flip
"EOF" // string doesn't matter here
};unsigned int cmdtoken[] = {
T_SKILL,
T_SKILL,
T_SKILL,
T_SKILL,
cmdtokenEOF
};#define LOOPDELAY 1000 // number of loops between actions
void loop() {
// This code runs repeatedly
// Put any change here if you want to change behaviors
if (loopct % 1000 == 0 )
{
loopct=0;
if (cmdtoken[phase]==cmdtokenEOF) phase=0;
strcpy(newCmd,cmd[phase]);
token=cmdtoken[phase++];
newCmdIdx=1;
}
loopct++;reaction();
}The robot is better than the cheap toys, but it still lacks many sensors. You can add on a few simple sensors that appear to mount in the dog’s mouth, or you can replace its head with an arm if you opt for beefy enough servos.
Of course, we’ve seen plenty of robot dogs. We want one, but we don’t know what we’d do with it. Any ideas?
-
@Caeri a macro in C (a #define -- not what it is in the snippet now) is essentially copy & paste that happens before compiling. it is powerful and cranky. can reduce repetition, replace features that the language doesn't have, like templates.
but you can also make silly macros that expand to unbalanced brackets, control statements, including return, goto and such.
C doesn't have the concept of modules or importing. a variable can be local to a lexical scope, local to a file, or global.
so -- yes: a macro may just insert the use of a variable wherever you expand it, without caring what it actually is. very much blindly.
-
@Caeri a macro in C (a #define -- not what it is in the snippet now) is essentially copy & paste that happens before compiling. it is powerful and cranky. can reduce repetition, replace features that the language doesn't have, like templates.
but you can also make silly macros that expand to unbalanced brackets, control statements, including return, goto and such.
C doesn't have the concept of modules or importing. a variable can be local to a lexical scope, local to a file, or global.
so -- yes: a macro may just insert the use of a variable wherever you expand it, without caring what it actually is. very much blindly.
-
Given an array arr for all valid pairs. Answer can be large. So, output answer modulo 1000000007Examples: Input: arr = 1, 2, 4, 4, 4 Output: 10 Approach: Store the frequency of each element and run a nested loop on the frequency array and find the required answer.Below is the implementation of the above approach: C++ // C++ implementation of the approach #include using namespace std; #define mod (int)(1e...
https://neveropen.tech/find-sum-of-a-i-a-j-for-all-valid-pairs/?fsp_sid=129735 -
@abstractcode you might think that, but I’ve seen the compiler pull in the entire pow() function (which is relatively gigantic) for a #define which actually wanted a 2^n function that you can just do with a bit shift…
-
@abstractcode you might think that, but I’ve seen the compiler pull in the entire pow() function (which is relatively gigantic) for a #define which actually wanted a 2^n function that you can just do with a bit shift…
-
Уёбище на пиздаболе блять*
Вот это он назвал читаемым если что
#define LDI_OP { \
ram_write(RAM, HL_RAM(D, E), ram_read(RAM, HL_RAM(H, L))); \
H += ((L++) == 0xFF); \
D += ((E++) == 0xFF); \
B -= ((C--) == 0x00); \
UPDATE_FLAGS__80880(0, B || C); \
}
*но я не говорил останавливаться -