It is currently Fri Nov 15, 2019 10:37 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sun May 12, 2019 10:20 pm 
Offline

Joined: Thu Apr 18, 2019 9:13 am
Posts: 161
rainwarrior wrote:
Also if you wait long enough things that everybody implements anyway do usually eventually make it into the standard spec.


Only if it's something that the authors of the Standard hadn't expected to be supported by any compiler writers who weren't being deliberately obtuse. Unfortunately, the authors of the Standard are unwilling to make clear that the Standard was never intended to forbid all of the stupid things compilers might do that would make them unsuitable for many purposes, but instead relied upon compiler writers being capable of exercising sound judgment in such things. The authors of the Standard have said that they'd expect most compilers to process something like:

Code:
unsigned mul_mod_65536(unsigned short x, unsigned short y) { return (x*y) & 0xFFFF; }


There was no need to mandate that the multiplication be processed as unsigned because implementations where it would make sense to process it that way would behave in that fashion with or without a mandate. The only situations where the authors would have expected a mandate would matter would be those where some other treatment would be more useful for some reason (e.g. on ones'-complement hardware, where making the result be accurate for values larger than INT_MAX would require an extra correction step), and in those cases the authors of the Standard saw no reason to prohibit the more useful treatment.


Top
 Profile  
 
PostPosted: Sun May 12, 2019 11:39 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7746
Location: Chexbres, VD, Switzerland
rainwarrior wrote:
Standard C maybe, but that's also why most compilers have extensions like __declspec(align), or __attribute__ ((aligned)). There's a lot of very practical ways to address domain specific problems when you actually allow domain specific solutions.

Also if you wait long enough things that everybody implements anyway do usually eventually make it into the standard spec.

This is also extremely ugly and unelegant.


Top
 Profile  
 
PostPosted: Mon May 13, 2019 2:58 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7629
Location: Canada
Bregalad wrote:
This is also extremely ugly and unelegant.

In practice, not really? You put the declspec/attribute in a single typedef and reuse it as much as you want with whatever name you choose. It's one line of code, probably in some header you don't need to look at much.

Code:
// define once
typedef __declspec(align(8)) unsigned int auint;

// use everywhere
auint x;
auint y,z;


Top
 Profile  
 
PostPosted: Mon May 13, 2019 3:38 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 4213
Location: A world gone mad
__attribute__ can certainly get pretty damn ugly. Here's one you have to do squelch warnings on newer gcc and clang when presented with functions like vfprintf/vsprintf() and friends, when using -Wformat-nonliteral (which I believe is brought in via -Wall or -Wextras, I forget which):
Code:
__attribute__((__format__ (__printf__, 1, 0)))
void status(const char *fmt, ...)
{
    va_list argp;

    va_start(argp, fmt);
    vfprintf(stdout, fmt, argp);
    va_end(argp);
    fflush(statusfp);
}

The 1 there is critical: it's the positional location of the formatting parameter. So, the number has to change depending on where that fmt argument happens to be, order-wise. Eventually I ceased writing/using "helper functions" of this sort and used the libc ones directly, solely to avoid this madness. (Oh, also, tools like Valgrind tend to get really pissy about all of this -- and rightfully so.)

I certainly wish there was a... I don't know how to put it -- cleaner and more "simply declared"? -- way to request alignment on data types (esp. within structs). I imagine Bregalad feels similarly. Ah well, no PL is perfect; at least we have *something*.


Top
 Profile  
 
PostPosted: Mon May 13, 2019 3:51 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7629
Location: Canada
koitsu wrote:
I certainly wish there was a... I don't know how to put it -- cleaner and more "simply declared"? -- way to request alignment on data types (esp. within structs).

The third link in my post above was to the C++11 alignas keyword, which is exactly that. Wish granted.

I brought up __declspec and __attribute__ to point out that compiler authors have been supplementing the standard to address needs like this since the very beginning.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: MSN [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group