Sujet : Re: question about linker
De : bc (at) *nospam* freeuk.com (Bart)
Groupes : comp.lang.cDate : 07. Dec 2024, 20:02:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vj263c$396ln$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
User-Agent : Mozilla Thunderbird
On 07/12/2024 17:58, David Brown wrote:
On 07/12/2024 17:52, Bart wrote:
f ( ) ;
f ( x , y , z ) ;
++ p . x ;
q = ( void ) p ;
label :
f ( x , y , z ) ;
a [ i + 1 ] ;
>
That is just differently bad from "f(x,y,z);" and "q=(void*)p;". Too much space is bad spacing,
You specifically praised Forth for requiring spaces between tokens, which is exactly what this code has.
I know this won't cut any ice, as nothing I can possibly write will ever make the slightest bit of difference, but in C you write stuff like this:
No, in C /I/ don't write anything of the sort - nor do most C programmers. And I don't believe you write functions with 8 parameters in your language either. At the very least, these would be highly unusual.
This is the real example it was based on (here using pass-by-reference):
proc fastidct8(int &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8) =
That itself was based on some original C which passed an array.
But because the values in the caller were not always consecutive (they were a column of a table), they needed copying into an array first, the function called, then copied back to the array since the function changes them.
Passing individual argument looked more efficient and tidier.
I'm sure it happens in C that several consecutive parameters have the same type, but there is no way to express that without repeating the type. Another real example:
static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
At least least this doesn't use a type like 'int32_t' otherwise it would be even longer, likely to overflow the line, and would obscure the names of the parameters. Just seeing how many there are becomes harder.
But even this would look far better as:
static void *stbi__malloc_mad4(int a, b, c, d, add)
(You can keep the 'int add' to emphasise that the first 4 are meant to share the same type, and it's not just coincidence.)
Don't forget the separate declaration, which repeats the parameters, that an exported function might need, as shown here:
extern int bn_add (Bignum c, Bignum a, Bignum b); # in .h file
int bn_add (Bignum c, Bignum a, Bignum b) { # in .c file
'Bignum' is written 6 times. This was ported from this version in my syntax:
export proc bn_addu(bignum dest, a, b) =
Here, 'bignum' is written only once. (The 'export' is needed if this build into an independent binary, such as a DLL, so that it is exported.)