Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #106482
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Array allocated on stack or heap |
| Date | 2017-03-19 13:52 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <oaluoh$sbs$1@dont-email.me> (permalink) |
| References | (2 earlier) <oahe6s$1b6$1@dont-email.me> <oahf4s$55b$1@dont-email.me> <oahqce$fhe$1@dont-email.me> <oalpv8$v3o$1@dont-email.me> <oalsds$83n$1@dont-email.me> |
On 19/03/17 13:12, BartC wrote:
> On 19/03/2017 11:30, David Brown wrote:
>> On 18/03/17 00:12, jacobnavia wrote:
>
>> These "weird, small circuits" are the dominant type of processor. There
>> are vastly more small, limited microcontrollers around than x86 or PPC
>> processors.
>>
>> I am happy to agree that most C programmers will deal only with systems
>> that have a single simple stack (per thread). I just like to make it
>> clear that this is not the only way C is implemented - there are very
>> common, real-world C implementations that have no stack or make minimal
>> use of a stack. This is not just a hypothetical case, or very rare or
>> unusual devices.
>
>
> This has been discussed a few times but is it right that a language like
> C should be permanently crippled, so that it can continue to work on
> these tiny or oddball processors that can barely be termed computers. Or
> should it be split?
>
There would be a reasonable argument for a split, /if/ the language were
being "crippled" by support for more limited (or outdated) systems. But
I don't believe that is the case. In this example, what benefit would
there be to people writing portable C code that they expect to run
mainly on PC's, if they knew that all there target systems had a
hardware stack?
(Note that there is already a split - between "hosted C environments"
and "free-standing C environments". You can read about the difference
in the standards.)
> That is, allow a streamlined version that is designed to work on what
> most people think of as a computer.
>
> Take the basic types for example:
>
> In Java, the types {byte, short, int, long} have widths {8, 16, 32, 64}.
>
> In C#, the types {sbyte, short, int, long} have widths {8, 16, 32, 64}.
>
> In Rust, they seem to be {i8, i16, i32, i64} (you can guess the widths).
>
> In Go, they are {int8, int16, int32, int64}.
>
> There's a common pattern. Now look at the types in C:
>
> {char, short, int, long, long long}
>
> For a start, there are five instead of four! Now for the widths (not
> checked, but you get the picture):
>
> { at least 8, but no longer than the width of short,
> at least 16 but not longer than int,
> at least 16 but not longer than long,
> at least 32 but not longer than long long
> at least 64}
>
> Plus the fact that all types are signed, except for char which may be
> signed OR unsigned, a fact you might not even know.
If you care whether "char" is signed or unsigned, you have been careless
in your coding.
>
> Anyone notice an obvious way that this mess could be tidied up?
Yes - you could introduce some size-specific types so that people who
needed tighter specifications for their integer types could say exactly
what they wanted. In order to make this system practical on a range of
systems, you would want the most specific types to be optional for
platforms where they could not work practically - you'd make this
"implementation dependent best effort". That way, common systems would
have full support, and others would support what they could.
That would be a new way to get standard sized integer types. You could
conveniently collect them into a header, called something like
<stdint.h> for brevity. If only someone had thought of that when C99
was written!
>
> And yes I know about the attempt to superimpose a more modern set of
> four types onto those five using: {int8_t, int16_t, int32_t, int64_t}
> with widths, if you are lucky, of {8, 16, 32, 64}.
>
> But that doesn't really cut it. For one thing, programs still use 'int'
> everywhere,
"An integer type of range at least -32767 .. 32767 that works
efficiently" is a good enough specification for a great many common
variables. And many programs have other limitations (such as the use of
Windows or *nix library calls) that imply "int" must be at least 32-bit
- again, that makes it a perfectly good choice.
> whose width is not fixed. They still use 'char' of unknown
> signedness.
Most uses of "char" are for storing letters or characters, or for
abstract byte storage - the signedness does not matter.
> Programs also tend to use 'size_t', whose size might be 32
> or 64, or maybe something else, and which is /probably/ unsigned (I'd
> need to check that).
And the exact size of size_t either does not matter, or what matters is
that the size is appropriate for the platform in question. Sometimes
platform-specific size is more useful than fixed size.
>
> Then there are still issues with the widths of float, double and long
> double. Plus the hoops to jump through to be able to print an intN_t type.
>
> If the ties to the old C that has to work on everything are cut, then a
> lot of things not just types could be tidied up.
>
A few things could be "tidied up" - but not many. I used to think as
you do here, until looking at it in more detail - there is surprisingly
little that could be specified more tightly that would actually be
significantly helpful in coding. And the potentially big gains would
come from making more drastic assumptions - such as fixing CHAR_BIT at 8
at the cost of excluding a good many DSP devices.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Array allocated on stack or heap Prashant Shah <pshah.mumbai@gmail.com> - 2017-03-16 22:58 -0700
Re: Array allocated on stack or heap Barry Schwarz <schwarzb@dqel.com> - 2017-03-16 23:57 -0700
Re: Array allocated on stack or heap Mark Storkamp <mstorkamp@yahoo.com> - 2017-03-17 12:44 -0500
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-17 11:26 -0700
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-17 20:38 +0100
Re: Array allocated on stack or heap Jerry Stuckle <jstucklex@attglobal.net> - 2017-03-17 16:08 -0400
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-18 00:03 +0100
Re: Array allocated on stack or heap Jerry Stuckle <jstucklex@attglobal.net> - 2017-03-17 20:54 -0400
Re: Array allocated on stack or heap John Bode <jfbode1029@gmail.com> - 2017-03-17 12:15 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-17 20:22 +0100
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-17 20:45 +0100
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-17 12:59 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-17 21:01 +0100
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-18 00:12 +0100
Re: Array allocated on stack or heap jameskuyper@verizon.net - 2017-03-17 16:25 -0700
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-17 17:08 -0700
Re: Array allocated on stack or heap Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-03-17 17:37 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-19 12:30 +0100
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 12:12 +0000
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-19 13:52 +0100
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 16:51 +0000
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-20 10:44 +0100
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-20 12:01 +0000
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-20 06:02 -0700
Re: Array allocated on stack or heap GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-20 14:54 +0100
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-20 07:28 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-20 16:43 +0100
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-20 09:02 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-21 10:11 +0100
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-21 02:48 -0700
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-21 08:19 -0700
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-21 08:17 -0700
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-21 09:06 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-21 17:32 +0100
Re: Array allocated on stack or heap Les Cargill <lcargill99@comcast.com> - 2017-03-25 15:14 -0500
Re: Array allocated on stack or heap Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-03-25 16:05 -0700
Re: Array allocated on stack or heap Les Cargill <lcargill99@comcast.com> - 2017-03-25 23:53 -0500
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-26 12:30 +0100
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-26 14:09 -0700
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-26 22:17 +0100
Re: Array allocated on stack or heap Robert Wessel <robertwessel2@yahoo.com> - 2017-03-26 21:52 -0500
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-27 13:06 +0100
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-27 10:10 -0700
Re: Array allocated on stack or heap Robert Wessel <robertwessel2@yahoo.com> - 2017-03-27 15:56 -0500
Re: Array allocated on stack or heap bartc <bc@freeuk.com> - 2017-03-27 22:48 +0100
Re: Array allocated on stack or heap Robert Wessel <robertwessel2@yahoo.com> - 2017-03-27 19:58 -0500
Re: Array allocated on stack or heap GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-20 14:56 +0100
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-20 15:34 +0100
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-20 09:28 -0700
Re: Array allocated on stack or heap bart4858@gmail.com - 2017-03-20 13:05 -0700
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-20 13:53 -0700
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-20 14:26 -0700
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-20 22:24 +0000
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-20 15:44 -0700
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-21 02:44 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-21 11:15 +0100
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-21 11:12 +0000
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-21 04:23 -0700
Re: Array allocated on stack or heap scott@slp53.sl.home (Scott Lurndal) - 2017-03-21 13:13 +0000
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-21 13:38 +0000
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-21 15:33 +0100
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-21 07:38 -0700
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-21 07:35 -0700
Re: Array allocated on stack or heap scott@slp53.sl.home (Scott Lurndal) - 2017-03-21 15:09 +0000
Re: Array allocated on stack or heap Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-19 13:05 +0000
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 13:27 +0000
Re: Array allocated on stack or heap GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-19 14:26 +0100
Re: Array allocated on stack or heap Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-19 13:34 +0000
Re: Array allocated on stack or heap GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-19 14:35 +0100
Re: Array allocated on stack or heap Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-19 13:36 +0000
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 14:00 +0000
Re: Array allocated on stack or heap Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-19 19:00 +0000
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 19:24 +0000
Re: Array allocated on stack or heap Ian Collins <ian-news@hotmail.com> - 2017-03-20 08:45 +1300
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-19 14:32 -0700
Re: Array allocated on stack or heap Ian Collins <ian-news@hotmail.com> - 2017-03-20 16:16 +1300
Re: Array allocated on stack or heap Gareth Owen <gwowen@gmail.com> - 2017-03-20 18:58 +0000
Re: Array allocated on stack or heap raltbos@xs4all.nl (Richard Bos) - 2017-03-24 09:17 +0000
Re: Array allocated on stack or heap Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-03-19 20:50 +0000
Re: Array allocated on stack or heap GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-19 14:10 +0100
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 13:38 +0000
Re: Array allocated on stack or heap GOTHIER Nathan <nathan.gothier@gmail.com> - 2017-03-19 14:49 +0100
Re: Array allocated on stack or heap luser droog <luser.droog@gmail.com> - 2017-03-20 07:59 -0700
Re: Array allocated on stack or heap Jerry Stuckle <jstucklex@attglobal.net> - 2017-03-19 10:57 -0400
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 16:14 +0000
Re: Array allocated on stack or heap Jerry Stuckle <jstucklex@attglobal.net> - 2017-03-19 15:53 -0400
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 20:37 +0000
Re: Array allocated on stack or heap Jean-Marc Bourguet <jm@bourguet.org> - 2017-03-19 23:09 +0100
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 22:38 +0000
Re: Array allocated on stack or heap Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-03-19 16:21 -0700
Re: Array allocated on stack or heap Ian Collins <ian-news@hotmail.com> - 2017-03-20 16:18 +1300
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-20 11:06 +0100
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-20 11:00 +0100
Re: Array allocated on stack or heap supercat@casperkitty.com - 2017-03-19 08:53 -0700
Re: Array allocated on stack or heap Jerry Stuckle <jstucklex@attglobal.net> - 2017-03-17 16:11 -0400
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-17 13:35 -0700
Re: Array allocated on stack or heap Chad <cdalten@gmail.com> - 2017-03-17 14:00 -0700
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-17 23:57 +0100
Re: Array allocated on stack or heap Ian Collins <ian-news@hotmail.com> - 2017-03-18 12:42 +1300
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-18 00:45 +0100
Re: Array allocated on stack or heap Chad <cdalten@gmail.com> - 2017-03-18 14:17 -0700
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-19 19:21 +0100
Re: Array allocated on stack or heap already5chosen@yahoo.com - 2017-03-19 15:00 -0700
Re: Array allocated on stack or heap BartC <bc@freeuk.com> - 2017-03-19 22:16 +0000
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-19 23:57 +0100
Re: Array allocated on stack or heap Keith Thompson <kst-u@mib.org> - 2017-03-19 16:15 -0700
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-20 12:24 +0100
Re: Array allocated on stack or heap scott@slp53.sl.home (Scott Lurndal) - 2017-03-20 13:24 +0000
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-19 13:21 +0100
Re: Array allocated on stack or heap John Bode <jfbode1029@gmail.com> - 2017-03-17 14:30 -0700
Re: Array allocated on stack or heap jacobnavia <jacob@jacob.remcomp.fr> - 2017-03-17 23:59 +0100
Re: Array allocated on stack or heap Jerry Stuckle <jstucklex@attglobal.net> - 2017-03-17 21:02 -0400
Re: Array allocated on stack or heap David Brown <david.brown@hesbynett.no> - 2017-03-19 13:26 +0100
csiph-web