🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Paul D. DeRocco Sat, 17 Feb 1996 12:28
Numeric literal formats
#3449
Author: Paul D. DeRocco
Date: Sat, 17 Feb 1996 12:28
22 lines
1471 bytes
Why, oh why, aren't we allowed to write binary numbers in C++? The 
standard could trivially be extended by allowing binary numbers to be 
written, prefixed with 0b, or perhaps 0y. This makes bit masks _much_ 
easier to read. And it wouldn't break any presently legal program.

Another related improvement would be to allow embedded underscores in 
numbers, for clarity. 1_000_000_000 is obviously a billion, while 
1000000000 is not so obviously a billion. Same for 0x8000_0000, or 
0y0001_1110_0000_0000. Again, it doesn't break anything.

Oh heck, I might as well throw this in. Why isn't there an escape for 
escape? That is, why can't \e be defined as \x1B, since it's such a 
common control character?

-- 

Ciao,
Paul D. DeRocco
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Re: Numeric literal formats
#3490
Author: Michael Cook
Date: Mon, 19 Feb 1996 02:30
11 lines
1110 bytes
>>>>> "P" == "Paul D DeRocco" <pderocco@ix.netcom.com> writes:

 P> Oh heck, I might as well throw this in. Why isn't there an escape for 
 P> escape? That is, why can't \e be defined as \x1B, since it's such a 
 P> common control character?

What would \e mean if the character set were not ASCII?
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Re: Numeric literal formats
#3352
Author: James Kanze US/ESC 60/3/141 #407...
Date: Tue, 20 Feb 1996 05:50
31 lines
2139 bytes
In article <r4g2c8lcrp.fsf@erawan.cognex.com> Michael Cook
<mcook@cognex.com> writes:

|> >>>>> "P" == "Paul D DeRocco" <pderocco@ix.netcom.com> writes:

|>  P> Oh heck, I might as well throw this in. Why isn't there an escape for 
|>  P> escape? That is, why can't \e be defined as \x1B, since it's such a 
|>  P> common control character?

|> What would \e mean if the character set were not ASCII?

I was about to post the same thing, then it occured to me that this
argument is equally valid concerning \a or \v (or for that matter,
probably everything but \n).

The other control characters are defined in terms of their semantics,
and not the code.  I'm not sure how the standard could define the
semantics of escape; this may be the reason why it isn't there.

--
James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, itudes et rialisations en logiciel orienti objet --
                -- A la recherche d'une activiti dans une region francophone
---
[ To submit articles: try just posting with your news-reader.
                      If that fails, use mailto:std-c++@ncar.ucar.edu
  FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Re: Numeric literal formats
#3374
Author: Kevlin A P Henney
Date: Tue, 20 Feb 1996 18:55
71 lines
3049 bytes
In article <3125C1DC.35AE@ix.netcom.com>
           pderocco@ix.netcom.com "Paul D. DeRocco" writes:

> Why, oh why, aren't we allowed to write binary numbers in C++? The 
> standard could trivially be extended by allowing binary numbers to be 
> written, prefixed with 0b, or perhaps 0y. This makes bit masks _much_ 
> easier to read. And it wouldn't break any presently legal program.

You might like to try the following:

	template<int digit> struct bit;

	struct bit<0> { enum { value = 0 }; };

	struct bit<1> { enum { value = 1 }; };

	template<int digits> struct bin;

	struct bin<0> { enum { value = 0 }; };

	template<int digits> struct bin
	{
		enum
		{
			value =	bin<digits / 10>::value * 2 +
				bit<digits % 10>::value
		};
	};

Used as

	bin<1101>::value
	bin<11001100>::value

Catches as illegal

	bin<12345>::value
	bin<011001>::value

If nothing else, the code is a good source of amusement -- present it to your
colleagues w/ the names changed to perplex the innocent :-)

Seriously, this is practical w/i the constraints of 32 bit ints and <= 10 bit
bit specs, and for compilers using the old specialization syntax (ie. the
majority).

> Another related improvement would be to allow embedded underscores in 
> numbers, for clarity. 1_000_000_000 is obviously a billion, while 
> 1000000000 is not so obviously a billion. Same for 0x8000_0000, or 
> 0y0001_1110_0000_0000. Again, it doesn't break anything.

Alternatively we could try for space separation and handle adjacent literals
as one, as is done w/ string literals:

	1 000 000 000
	0x 8000 0000
	0.12345 67890

:->
_______________________________________________________________________

  Kevlin A P Henney        2sdg Ltd        kevlin@two-sdg.demon.co.uk
  "What happens to the hole when the cheese is gone?"  Bertolt Brecht
_______________________________________________________________________
---
[ To submit articles: Try just posting with your newsreader.  If that fails,
                      use mailto:std-c++@ncar.ucar.edu
  FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std.c++-request@ncar.ucar.edu 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads