[Freeciv-Dev] [patch #2811] Static (compile-time) assert mechanism

2011-09-06 Thread Jacob Nevins

Update of patch #2811 (project freeciv):

  Status:  Ready For Test => Done   
 Open/Closed:Open => Closed 


___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [patch #2811] Static (compile-time) assert mechanism

2011-09-04 Thread Jacob Nevins

Follow-up Comment #4, patch #2811 (project freeciv):

Minor changes: rebased, tweaked comments, verified example assertion. I plan
to commit this soon.

(file #14032)
___

Additional Item Attachment:

File name: trunk-static-assert-bis.diff   Size:3 KB


___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [patch #2811] Static (compile-time) assert mechanism

2011-09-04 Thread Jacob Nevins

Follow-up Comment #3, patch #2811 (project freeciv):

> At least g++ side has had static_assert since 4.3. One should 
> check if also gcc supports it. 
Answer appears to be: only since 4.6
. I think we probably have to wait
a year or two for that version to be used "99.5% of the time" (well, at least
I don't even have 4.5 yet; 4.3 is standard on my system).
Also, it's not clear to me whether you can get at it without specifying
"-std=c1x", and I'm not sure if our code is ready to be compiled with that
option.

So, I'll probably stick with the nasty version in the patch for now.

___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [patch #2811] Static (compile-time) assert mechanism

2011-07-16 Thread Marko Lindqvist

Follow-up Comment #2, patch #2811 (project freeciv):

I haven't looked your patch at all, but...

> This idiom doesn't map onto the static_assert(constant-expression, "error
message") pattern that's apparently coming in a future C standard

Well, no standard with static_assert has been released yet, but that has
never stopped gcc folk from implementing things that are already in
proposal... At least g++ side has had static_assert since 4.3. One should
check if also gcc supports it.
If it does: as gcc is the compiler used for freeciv compilation 99.5% of the
time, I'd simply add configure check if compiler supports static_assert(), and
define our own macro accordingly (either use static_assert, or do nothing).

___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [patch #2811] Static (compile-time) assert mechanism

2011-07-16 Thread Jacob Nevins

Update of patch #2811 (project freeciv):

  Status: In Progress => Ready For Test 

___

Follow-up Comment #1:

Proof of concept attached.
(Note that I haven't actually verified that the specific condition I'm
asserting as an example is correct yet...)

(file #13594)
___

Additional Item Attachment:

File name: trunk-static-assert.diff   Size:2 KB


___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev


[Freeciv-Dev] [patch #2811] Static (compile-time) assert mechanism

2011-07-16 Thread Jacob Nevins

URL:
  

 Summary: Static (compile-time) assert mechanism
 Project: Freeciv
Submitted by: jtn
Submitted on: Sat Jul 16 23:35:33 2011
Category: general
Priority: 5 - Normal
  Status: In Progress
 Privacy: Public
 Assigned to: jtn
Originator Email: 
 Open/Closed: Open
 Discussion Lock: Any
 Planned Release: 2.4.0

___

Details:

For maintainability, it's occasionally useful to be able to make the build
fail if certain conditions are not true, usually relating to build-time
tweakables or system limits.

Bug #18087 is a case in point; MAP_MAX_SIZE relies on MAX_DBV_LENGTH having a
certain minimum value, and this is currently commented, but it would be better
if the build failed hard when someone increased MAP_MAX_SIZE without noticing
the comment, rather than them having to debug some subtle failure. (OK, in
this case you run into a run-time assertion failure pretty quickly, but in
some other case you might not happen to tickle that code path in your
testing.)

This isn't a standard facility in the C language (yet), but there are a
number of well-known techniques for doing this in C, each with their
advantages and drawbacks (particularly generation of warnings, which matters
to us because we run with -Werror).

Googling found some surveys of available techniques here
, here
 (old!), and here
,
for example.

I'm leaning toward this one:


#define FC_STATIC_ASSERT(cond, tag) enum { static_assert_ ## tag = 1 /
(!!(cond)) }

FC_STATIC_ASSERT(MAP_MAX_SIZE * 1000 <= MAX_DBV_LENGTH,
map_too_big_for_bitvector);


which, if it fails, throws the following error on my system:


In file included from ../packets.h:29,
 from ../game.h:33,
 from aisupport.c:26:
../map.h:571: error: division by zero
../map.h:571: error: enumerator value for
‘static_assert_map_too_big_for_bitvector’ is not an integer constant


Ugly, but effective.

(It's a shame this idiom doesn't map onto the
static_assert(constant-expression, "error message") pattern that's apparently
coming in a future C standard, but I haven't found a satisfactory technique
that does.)




___

Reply to this item at:

  

___
  Message sent via/by Gna!
  http://gna.org/


___
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev