On Monday, January 17, 2022 at 4:51:12 PM UTC+1, Tim Rentsch wrote:
Marco Munari <[email protected]> writes:
I thought it could be nice to introduce condition inside macro
definition, to produce less jumping code (so compiler can output
bigger but more efficient code with concise definition)
a syntax could be defined by adding an optional #defif (due to the
late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the
macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,...) #defelse ...
usable with macro(5,x)
expansion parameter that i called #N need to be a constant provided
to the expansion engine, the # prefix I indicated here is not a
syntax necessity because it can be deduced by the fact that this
parameters appears in the #defif condition which also must be fully valuable during preprocessing (just a bit more powerful
preprocessing) [...]
[I wrote this first post encountering the message
"Your message has not finished sending yet."(google)
when trying to escape a buggy group post editing in iPad,
buggy because the keyboard was totally covering the insert point...
(I miss NNTP interfaced with gnus in emacs...)]
the binary search three example should have been consistent to the following: #define f(#N,bt,a) \
#defif(#N>0) \
bt == NULL ? bt : (a == bt->val) \
? bt : (a < bt->val) \
? f(#N-1,bt->left,a) \
: f(#N-1,bt->right,a) \
#defelse \
g(bt,a)
/* f macro definition ended here, below the example continue with the use */ struct {int val; binarytree *left,*right} binarytree;
binarytree* g(binarytree* bt, int a) {
return f(5,bt,a); /* recursive batch dept 5 is stored only here */
}
[Also, the character shown in inclusive replies with "?" was "..."
but transformed by iPad in an unicode single character of three dots,
now I replaced to the original three dots also inside my inclusion
which obviously meant unspecified traditional #define content]
It's an interesting idea. There are details that need to be
explored and understood first. Also I think it would be better
if expanded and generalized, perhaps along the lines of 'cond'
in lisp, or alternatively with ?# :# as preprocessing if/else.
Hmmm...
I'm favorable to any changes to the syntax I proposed,
including something a less powerful but simpler as
a number in the square brakes before the macro name
saying how many recursive expansion are permitted
#define f(bt,a) \
bt == NULL ? bt : (a == bt->val) \
? bt : (a < bt->val) \
? [5]f(bt->left,a) \
: [5]f(bt->right,a) \
#defelse \
g(bt,a)
You mentioned lisp, yes and why not lisp... I mean even lisp syntax!
limited to that (#define)context (which might exceptionally if you like,
save from the obligation of end lines with backslash when parenthesis
are not balanced at the end of #define line)
(cond CLAUSES...) (returning empty expansion where
returns nil when all clausole are unsatisfied).
Anyway (cond) could be along the line of #defswitch ... #defcase
wich is to #defif / #defelseif / #defelse (or without the prefix def)
Interesting also your concise syntax ?# :# (or maybe you meant ... #? ... #: ...
as the dash come before in preprocessing recognition) as a form of ... ? ... : ...
but with dash used as preprocessing-only condition, with the same
functionality that I invoked with #defif / #defelse), it can be both
CPP forms, as the C has the dual.
As it was not introduced for so long to C/CPP, I welcome to open the discussion and make a wise choice, which include cases of possible and opportune use studio.
Actually I have in mind recursion batch as a case where this is effectively needed/beneficial, but the case of generic constant condition... I'm not too sure is a generic benefit for maintenance and code understanding (furthermore there is also already the possibility of #if before the #define for different and constant #define),
maybe the [number]macro on invocation syntax within the #define macro
is sufficient as well as missing to permit something quite essential.
Let's think about cases of essential use
I'm also considering that there are a series of tools as Visual Studio, gdb interpreation of macro expansion information saved in debug compiled file format, which have some expectations on preprocessing, and the change
should be so welcome
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)