dynamic mem alloc q | | |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define BUF_MAX 80
int main (void) {
char buf[BUF_MAX];
unsigned long l;
size_t s;
printf("give me a number less than a third billion: \n");
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtoul(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
/* add code here */
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}
/* int *dynarray;
dynarray = malloc(l * sizeof(long)); */
/* end source */
I seek to dynamically allocate memory of an array of unsigned longs with
array size determined from an unsigned long from the keyboard. With program
control as it exists now, it would seem that I would get the business done
where I have marked
/* add code here */
Do I need to redesign program control in order not to have a leak the size
of Texas? Joe | | | | re: dynamic mem alloc q
Joe Smith schrieb:[color=blue]
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
>
>
> #define BUF_MAX 80
>
> int main (void) {
> char buf[BUF_MAX];
> unsigned long l;
> size_t s;
> printf("give me a number less than a third billion: \n");
> while(fgets(buf, BUF_MAX, stdin) != NULL) {
> if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
> errno = 0;
> l = strtoul(buf, NULL, 10);
> if (errno == ERANGE) {
> printf("number out of range!\n");
> } else {[/color]
Note: The values of l indicating potential errors are 0
and ULONG_MAX; as you want to allocate storage neither for 0
nor for ULONG_MAX array elements (at least if by "billion" you
mean 1e9), you can just test for >0 and <= 333333333UL (assuming
you mean "a third of a" by "third") in the first place.
Only if you have a failure there, I'd check using strspn() or
repeat the strtoul() call preceded by errno = 0.
This is more straightforward and entirely sufficient.
[color=blue]
>
> /* add code here */
>
> }
> } else {
> while(s--)
> putchar(' ');
> putchar('^');
> printf(" invalid character\n");
> }
> }
>
> return 0;
> }
>
> /* int *dynarray;
> dynarray = malloc(l * sizeof(long)); */
> /* end source */
>
> I seek to dynamically allocate memory of an array of unsigned longs with
> array size determined from an unsigned long from the keyboard. With program
> control as it exists now, it would seem that I would get the business done
> where I have marked
> /* add code here */
> Do I need to redesign program control in order not to have a leak the size
> of Texas?[/color]
Well, don't forget to free() allocated storage :-)
Apart from that, only forgetting to check against l != 0 can be a
problem.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address. | | | | re: dynamic mem alloc q
"Michael Mair" penned:[color=blue]
> Joe Smith schrieb:[color=green]
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <string.h>
>> #include <errno.h>
>>
>>
>> #define BUF_MAX 80
>>
>> int main (void) {
>> char buf[BUF_MAX];
>> unsigned long l;
>> size_t s;
>> printf("give me a number less than a third billion: \n");
>> while(fgets(buf, BUF_MAX, stdin) != NULL) {
>> if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
>> errno = 0;
>> l = strtoul(buf, NULL, 10);
>> if (errno == ERANGE) {
>> printf("number out of range!\n");
>> } else {[/color]
>
> Note: The values of l indicating potential errors are 0
> and ULONG_MAX; as you want to allocate storage neither for 0
> nor for ULONG_MAX array elements (at least if by "billion" you
> mean 1e9), you can just test for >0 and <= 333333333UL (assuming
> you mean "a third of a" by "third") in the first place.
> Only if you have a failure there, I'd check using strspn() or
> repeat the strtoul() call preceded by errno = 0.
> This is more straightforward and entirely sufficient.[/color]
'm' and 'b' are both labials in english. 'onnen' and 'arden' in german
don't penetrate the stupor of thought that a lot of persons who have who use
these words, i.e. regarding largish numbers. I would have thought that a
zero input would have succumbed to the ERANGE flag. It seeems to me,
however, that you're hinting my sniped code needs a tune-up here.
[color=blue][color=green]
>>
>> /* add code here */
>>
>> }
>> } else {
>> while(s--)
>> putchar(' ');
>> putchar('^');
>> printf(" invalid character\n");
>> }
>> }
>>
>> return 0;
>> }
>>
>> /* int *dynarray;
>> dynarray = malloc(l * sizeof(long)); */
>> /* end source */
>>
>> I seek to dynamically allocate memory of an array of unsigned longs with
>> array size determined from an unsigned long from the keyboard. With
>> program control as it exists now, it would seem that I would get the
>> business done where I have marked
>> /* add code here */
>> Do I need to redesign program control in order not to have a leak the
>> size of Texas?[/color]
>
> Well, don't forget to free() allocated storage :-)
> Apart from that, only forgetting to check against l != 0 can be a
> problem.[/color]
I'll give it hell tonight. Joe | | | | re: dynamic mem alloc q
Joe Smith wrote:[color=blue]
> "Michael Mair" penned:[color=green]
> > Joe Smith schrieb:[color=darkred]
> >> #include <stdio.h>
> >> #include <stdlib.h>
> >> #include <string.h>
> >> #include <errno.h>
> >>
> >>
> >> #define BUF_MAX 80
> >>
> >> int main (void) {
> >> char buf[BUF_MAX];
> >> unsigned long l;
> >> size_t s;
> >> printf("give me a number less than a third billion: \n");
> >> while(fgets(buf, BUF_MAX, stdin) != NULL) {
> >> if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
> >> errno = 0;
> >> l = strtoul(buf, NULL, 10);
> >> if (errno == ERANGE) {
> >> printf("number out of range!\n");
> >> } else {[/color]
> >
> > Note: The values of l indicating potential errors are 0
> > and ULONG_MAX; as you want to allocate storage neither for 0
> > nor for ULONG_MAX array elements (at least if by "billion" you
> > mean 1e9), you can just test for >0 and <= 333333333UL (assuming
> > you mean "a third of a" by "third") in the first place.
> > Only if you have a failure there, I'd check using strspn() or
> > repeat the strtoul() call preceded by errno = 0.
> > This is more straightforward and entirely sufficient.[/color]
>
> 'm' and 'b' are both labials in english. 'onnen' and 'arden' in german
> don't penetrate the stupor of thought that a lot of persons who have who use
> these words, i.e. regarding largish numbers. I would have thought that a
> zero input would have succumbed to the ERANGE flag. It seeems to me,
> however, that you're hinting my sniped code needs a tune-up here.[/color]
Below is the appropriate caveat I listed with the code when I
originally posted it:
"If the input contains only of whitespace or the minus sign the
converted value will be 0. "
The minus sign part does not, of course, apply to your version. The
word "contains" was supposed to be "consists".
I have tried to impress upon you the fact that the code was written to
meet a very specific need, what exactly are the needs *you* are trying
to accomidate?
Robert Gamble | | | | re: dynamic mem alloc q
Joe Smith schrieb:[color=blue]
> "Michael Mair" penned:[color=green]
>>Joe Smith schrieb:
>>[color=darkred]
>>>#include <stdio.h>
>>>#include <stdlib.h>
>>>#include <string.h>
>>>#include <errno.h>
>>>
>>>#define BUF_MAX 80
>>>
>>>int main (void) {
>>> char buf[BUF_MAX];
>>> unsigned long l;
>>> size_t s;
>>> printf("give me a number less than a third billion: \n");
>>> while(fgets(buf, BUF_MAX, stdin) != NULL) {
>>> if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
>>> errno = 0;
>>> l = strtoul(buf, NULL, 10);
>>> if (errno == ERANGE) {
>>> printf("number out of range!\n");
>>> } else {[/color]
>>
>>Note: The values of l indicating potential errors are 0
>>and ULONG_MAX; as you want to allocate storage neither for 0
>>nor for ULONG_MAX array elements (at least if by "billion" you
>>mean 1e9), you can just test for >0 and <= 333333333UL (assuming
>>you mean "a third of a" by "third") in the first place.
>>Only if you have a failure there, I'd check using strspn() or
>>repeat the strtoul() call preceded by errno = 0.
>>This is more straightforward and entirely sufficient.[/color]
>
> 'm' and 'b' are both labials in english. 'onnen' and 'arden' in german[/color]
ITYM 'onen' and 'arden'.[color=blue]
> don't penetrate the stupor of thought that a lot of persons who have who use
> these words, i.e. regarding largish numbers.[/color]
I am not sure what you are trying to achieve with these
"witticisms" of yours: There are two possible meanings of "billion"
in English, so the question was just to clarify whether you mean
1e9 or 1e12.
Especially in a newsgroup frequented by native speakers and
non-native speakers alike, everyone should take care to express his
or her intent clearly and concisely.
[color=blue]
> I would have thought that a
> zero input would have succumbed to the ERANGE flag. It seeems to me,
> however, that you're hinting my sniped code needs a tune-up here.[/color]
Why don't you just read the documentation of strtoul()?
It will tell you that 0 and ULONG_MAX are the only return values
that _can_ indicate errors. As you need neither, no further
preliminaries are necessary.
[color=blue][color=green][color=darkred]
>>>/* add code here */
>>>
>>> }
>>> } else {
>>> while(s--)
>>> putchar(' ');
>>> putchar('^');
>>> printf(" invalid character\n");
>>> }
>>> }
>>>
>>> return 0;
>>>}
>>>
>>>/* int *dynarray;
>>> dynarray = malloc(l * sizeof(long)); */
>>>/* end source */
>>>
>>>I seek to dynamically allocate memory of an array of unsigned longs with
>>>array size determined from an unsigned long from the keyboard. With
>>>program control as it exists now, it would seem that I would get the
>>>business done where I have marked
>>>/* add code here */
>>>Do I need to redesign program control in order not to have a leak the
>>>size of Texas?[/color]
>>
>>Well, don't forget to free() allocated storage :-)
>>Apart from that, only forgetting to check against l != 0 can be a
>>problem.[/color]
>
> I'll give it hell tonight. Joe[/color]
Good luck :-)
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address. | | | | re: dynamic mem alloc q
"Michael Mair"[color=blue]
> Joe Smith schrieb:[color=green]
>> "Michael Mair" penned:[color=darkred]
>>>Joe Smith schrieb:
>>>
>>>
>>>Note: The values of l indicating potential errors are 0
>>>and ULONG_MAX; as you want to allocate storage neither for 0
>>>nor for ULONG_MAX array elements (at least if by "billion" you
>>>mean 1e9), you can just test for >0 and <= 333333333UL (assuming
>>>you mean "a third of a" by "third") in the first place.
>>>Only if you have a failure there, I'd check using strspn() or
>>>repeat the strtoul() call preceded by errno = 0.
>>>This is more straightforward and entirely sufficient.[/color]
>>
>> 'm' and 'b' are both labials in english. 'onnen' and 'arden' in german[/color]
> ITYM 'onen' and 'arden'.[color=green]
>> don't penetrate the stupor of thought that a lot of persons who have who
>> use these words, i.e. regarding largish numbers.[/color]
>
> I am not sure what you are trying to achieve with these
> "witticisms" of yours: There are two possible meanings of "billion"
> in English, so the question was just to clarify whether you mean
> 1e9 or 1e12.
> Especially in a newsgroup frequented by native speakers and
> non-native speakers alike, everyone should take care to express his
> or her intent clearly and concisely.[/color]
I would object to my witticism needing to be regarded as a string literal
had the grammar been correct. Maybe we should say something, as I have
serially witnessed German-English discussions fly off the rails right here,
usually by the English speaker thinking 'Milliard' was a million. I will
use billion to mean 10^9 and trillion to mean 10^12 .
[color=blue]
>[color=green]
>> I would have thought that a zero input would have succumbed to the ERANGE
>> flag. It seeems to me, however, that you're hinting my sniped code needs
>> a tune-up here.[/color]
>
> Why don't you just read the documentation of strtoul()?
> It will tell you that 0 and ULONG_MAX are the only return values
> that _can_ indicate errors. As you need neither, no further
> preliminaries are necessary.[/color]
I'll get to it over cereal today.
[color=blue][color=green][color=darkred]
>>>>I seek to dynamically allocate memory of an array of unsigned longs with
>>>>array size determined from an unsigned long from the keyboard. With
>>>>program control as it exists now, it would seem that I would get the
>>>>business done where I have marked
>>>>/* add code here */
>>>>Do I need to redesign program control in order not to have a leak the
>>>>size of Texas?
>>>
>>>Well, don't forget to free() allocated storage :-)
>>>Apart from that, only forgetting to check against l != 0 can be a
>>>problem.[/color][/color][/color]
[snip]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define BUF_MAX 80
int main (void) {
char buf[BUF_MAX];
unsigned long l, i;
size_t s;
int *dynarray;
printf("give me a number less than a third billion: \n");
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtoul(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
/* dyn mem alloc */
dynarray = malloc((l+1) * sizeof(long));
if (dynarray != NULL)
{
/* populate array with the dummy's index */
for(i = 0;i <= l; ++ i) dynarray[i] = i;
/* output: print em all */
for(i = 0;i <= l; ++ i) printf("%lu %lu\n", i, l);
free(dynarray);
}
/* else code for unsuccessful malloc here */
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}
/* end source */
This compiles and seems to behave. At this point I wouldn't know what to do
with an unsuccessful malloc. This malloc was particularly effective when
gorgeous, blond Stephanie asked me whether what I was writing on the napkin
was difficult mathematics. I told her it wasn't easy. I tested for values
up to four million. It would seem quite possible that a computer might have
trouble storing one third of a billion longs. Joe | | | | re: dynamic mem alloc q
Joe Smith schrieb:[color=blue]
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
>
>
> #define BUF_MAX 80
>
> int main (void) {
> char buf[BUF_MAX];
> unsigned long l, i;
> size_t s;
> int *dynarray;
> printf("give me a number less than a third billion: \n");
> while(fgets(buf, BUF_MAX, stdin) != NULL) {
> if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
> errno = 0;
> l = strtoul(buf, NULL, 10);
> if (errno == ERANGE) {
> printf("number out of range!\n");
> } else {
>
> /* dyn mem alloc */
> dynarray = malloc((l+1) * sizeof(long));[/color]
Are you kidding?
In your OP, you wrote
,- <ec3e2dad@news.usenetmonster.com> -
I seek to dynamically allocate memory of an array of unsigned
longs with array size determined from an unsigned long from the
keyboard.
`----
Now, you are allocating memory and assign it to an int *
variable. The "sizeof(long)" does not help either and seems like
something having been forgotten when switching from long to int.
Note that around here, the following way of using malloc() is
recommended as least error prone way:
unsigned long *dynarray;
....
dynarray = malloc((l+1) * sizeof *dynarray);
[color=blue]
> if (dynarray != NULL)
> {
> /* populate array with the dummy's index */
> for(i = 0;i <= l; ++ i) dynarray[i] = i;[/color]
This assignment could overflow.
If you use your compiler at the highest warning level, it
probably will warn you about that.
[color=blue]
> /* output: print em all */
> for(i = 0;i <= l; ++ i) printf("%lu %lu\n", i, l);
> free(dynarray);
> }
> /* else code for unsuccessful malloc here */
>
> }
> } else {
> while(s--)
> putchar(' ');
> putchar('^');
> printf(" invalid character\n");
> }
> }
>
> return 0;
> }
> /* end source */[/color]
As mentioned in a previous post, I'd rather check for strtoul()s
possible error returns. This is probably more efficient and less
obscure than your method. It has the added benefit that you can
check whether the user input is in the required range and not in
the type range.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address. | | | | re: dynamic mem alloc q
"Michael Mair"[color=blue]
> Joe Smith schrieb:[/color]
[color=blue][color=green]
>> dynarray = malloc((l+1) * sizeof(long));[/color]
> Are you kidding?[/color]
Unfortunately, no.
[color=blue]
> In your OP, you wrote
> ,- <ec3e2dad@news.usenetmonster.com> -
> I seek to dynamically allocate memory of an array of unsigned
> longs with array size determined from an unsigned long from the
> keyboard.
> `----
> Now, you are allocating memory and assign it to an int *
> variable. The "sizeof(long)" does not help either and seems like
> something having been forgotten when switching from long to int.
> Note that around here, the following way of using malloc() is
> recommended as least error prone way:
> unsigned long *dynarray;
> ....
> dynarray = malloc((l+1) * sizeof *dynarray);
>[color=green]
>> if (dynarray != NULL)
>> {
>> /* populate array with the dummy's index */
>> for(i = 0;i <= l; ++ i) dynarray[i] = i;[/color]
>
> This assignment could overflow.
> If you use your compiler at the highest warning level, it
> probably will warn you about that.[/color]
The argument for mallocing an array would seem to consist of something that
indicates the the number of boxes you're going to have multplied by how much
memory each of those boxes is going to take. (An array is a bunch of boxes
in a line with numbers on the side. One thinks of it this way and takes his
pills. Mine are blue.) The (l+1) part indicates the number of boxes, and C
being what it is, I ordered an extra box for zero.
[color=blue]
> As mentioned in a previous post, I'd rather check for strtoul()s
> possible error returns. This is probably more efficient and less
> obscure than your method. It has the added benefit that you can
> check whether the user input is in the required range and not in
> the type range.[/color]
But just as soon as a figure out longs, I'm going to want longers.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define BUF_MAX 80
int main (void) {
char buf[BUF_MAX];
unsigned long l, i;
size_t s;
unsigned long *dynarray;
printf("give me a number less than a third billion: \n");
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtoul(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
/* dyn mem alloc */
dynarray = malloc((l+1) * sizeof(long));
if (dynarray != NULL)
{
/* populate array with the dummy's index */
for(i = 0;i <= l; ++ i) dynarray[i] = i;
/* output: print em all */
for(i = 0;i <= l; ++ i) printf("%lu %lu\n", i, l);
free(dynarray);
}
/* else code for unsuccessful malloc here */
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}
/* end source */
I believe that this addresses what Mr. Mair was getting at, but that a
pointer would need to be an unsigned long makes no sense to me. There
doesn't seem to be much you could do in that /*else code */ part other than
to
printf("give me a smaller number or get more RAM\n");
Joe | | | | re: dynamic mem alloc q
"Robert Gamble"[color=blue]
> Joe Smith wrote:[/color]
[code snipped][color=blue]
> Below is the appropriate caveat I listed with the code when I
> originally posted it:
>
> "If the input contains only of whitespace or the minus sign the
> converted value will be 0. "
>
> The minus sign part does not, of course, apply to your version. The
> word "contains" was supposed to be "consists".
>
> I have tried to impress upon you the fact that the code was written to
> meet a very specific need, what exactly are the needs *you* are trying
> to accomidate?[/color]
I've always cheated with io and C. Indeed, I think the sheer punishment
that is the io syntax in C led many on a path that would leave them hanging
out with the polymorphism wizard. My first endeavor is to improve my
syntax. When I've got enough of that remembered, renewed, modified, revised
and added, I would like to play with combinatorial-sized numbers. Joe | | | | re: dynamic mem alloc q
Joe Smith wrote:[color=blue]
>[/color]
.... snip ...[color=blue]
>
> I would object to my witticism needing to be regarded as a string
> literal had the grammar been correct. Maybe we should say
> something, as I have serially witnessed German-English discussions
> fly off the rails right here, usually by the English speaker
> thinking 'Milliard' was a million. I will use billion to mean 10^9
> and trillion to mean 10^12 .[/color]
The simple cure is to simply write "1e9" or "1e12" as needed, and
retire the confusing verbiage. Similarly, the use of ISO standard
date formats can avoid much confusion.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/> | | | | re: dynamic mem alloc q
Joe Smith schrieb:[color=blue]
> "Michael Mair"[color=green]
>>Joe Smith schrieb:[/color]
>[color=green][color=darkred]
>>>dynarray = malloc((l+1) * sizeof(long));[/color]
>>
>>Are you kidding?[/color]
>
> Unfortunately, no.
>[color=green]
>>In your OP, you wrote
>>,- <ec3e2dad@news.usenetmonster.com> -
>>I seek to dynamically allocate memory of an array of unsigned
>>longs with array size determined from an unsigned long from the
>>keyboard.
>>`----
>>Now, you are allocating memory and assign it to an int *
>>variable. The "sizeof(long)" does not help either and seems like
>>something having been forgotten when switching from long to int.
>>Note that around here, the following way of using malloc() is
>>recommended as least error prone way:
>> unsigned long *dynarray;
>> ....
>> dynarray = malloc((l+1) * sizeof *dynarray);
>>
>>[color=darkred]
>>>if (dynarray != NULL)
>>>{
>>>/* populate array with the dummy's index */
>>>for(i = 0;i <= l; ++ i) dynarray[i] = i;[/color]
>>
>>This assignment could overflow.
>>If you use your compiler at the highest warning level, it
>>probably will warn you about that.[/color]
>
> The argument for mallocing an array would seem to consist of something that
> indicates the the number of boxes you're going to have multplied by how much
> memory each of those boxes is going to take. (An array is a bunch of boxes
> in a line with numbers on the side. One thinks of it this way and takes his
> pills. Mine are blue.) The (l+1) part indicates the number of boxes, and C
> being what it is, I ordered an extra box for zero.[/color]
If dynarray is a pointer to int, dynarray[i] will access a
signed int value. Assigning i, an unsigned long value, to
dynarray[i] may lead to signed integer overflow.
<snip>[color=blue]
> unsigned long l, i;[/color]
<snip>[color=blue]
> unsigned long *dynarray;[/color]
<snip>[color=blue]
> dynarray = malloc((l+1) * sizeof(long));[/color]
<snip>[color=blue]
> for(i = 0;i <= l; ++ i) dynarray[i] = i;[/color]
<snip>[color=blue]
> /* end source */
> I believe that this addresses what Mr. Mair was getting at, but that a
> pointer would need to be an unsigned long makes no sense to me.[/color]
No. Not the pointer is an unsigned long -- what it points to is of
type unsigned long. As you stated that you want an array l of unsigned
long (now rather an array l+1 of unsigned long), it is an error
to use a pointer to int: It is the wrong pointer type, dynarray[i]
consequently will be of type int instead of type unsigned long.
[color=blue]
> There
> doesn't seem to be much you could do in that /*else code */ part other than
> to
> printf("give me a smaller number or get more RAM\n");[/color]
The way the program is structured, that is about it.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address. | | | | re: dynamic mem alloc q
"Joe Smith" <grumpy196884@netzero.net> wrote:
[color=blue]
> I would object to my witticism needing to be regarded as a string literal
> had the grammar been correct. Maybe we should say something, as I have
> serially witnessed German-English discussions fly off the rails right here,
> usually by the English speaker thinking 'Milliard' was a million. I will
> use billion to mean 10^9 and trillion to mean 10^12 .[/color]
Ah, but _that_, OTOH, has the disadvantage that you're only compatible
with USAnians and USAnianised[1] Britons[2]. The rest of the world knows
that a billion is 10e12. What's more, this incompatibility is harder to
detect than using milliard.
Richard
[1] Or should that be *USAnianized?
[2] More and more each day, and President^WPM Blair isn't helping. | | | | re: dynamic mem alloc q
Richard Bos said:
[color=blue]
> "Joe Smith" <grumpy196884@netzero.net> wrote:
>[color=green]
>> I would object to my witticism needing to be regarded as a string literal
>> had the grammar been correct. Maybe we should say something, as I have
>> serially witnessed German-English discussions fly off the rails right
>> here,
>> usually by the English speaker thinking 'Milliard' was a million. I will
>> use billion to mean 10^9 and trillion to mean 10^12 .[/color]
>
> Ah, but _that_, OTOH, has the disadvantage that you're only compatible
> with USAnians and USAnianised[1] Britons[2].[/color]
And, apparently, the French.
"Milliard" is, of course, the proper way to describe 1,000,000,000.
[color=blue]
> The rest of the world knows that a billion is 10e12.[/color]
We also know the proper end at which to open our eggs.
[color=blue]
> What's more, this incompatibility is harder to
> detect than using milliard.[/color]
I will continue to use "billion" for 1e12 and "milliard" for 1e9, and if
people wish to misunderstand me, that is their problem, not mine.
[color=blue]
> [...] President^WPM Blair isn't helping.[/color]
Don't blame me. I didn't vote for him. (Ever.)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) | | | | re: dynamic mem alloc q
"Richard Heathfield"[color=blue]
> Richard Bos said:[color=green]
>> "Joe Smith"[/color][/color]
[color=blue][color=green][color=darkred]
>>> I would object to my witticism needing to be regarded as a string
>>> literal
>>> had the grammar been correct. Maybe we should say something, as I have
>>> serially witnessed German-English discussions fly off the rails right
>>> here,
>>> usually by the English speaker thinking 'Milliard' was a million. I
>>> will
>>> use billion to mean 10^9 and trillion to mean 10^12 .[/color]
>>
>> Ah, but _that_, OTOH, has the disadvantage that you're only compatible
>> with USAnians and USAnianised[1] Britons[2].[/color]
>
> And, apparently, the French.
>
> "Milliard" is, of course, the proper way to describe 1,000,000,000.
>[color=green]
>> The rest of the world knows that a billion is 10e12.[/color]
>
> We also know the proper end at which to open our eggs.
>[color=green]
>> What's more, this incompatibility is harder to
>> detect than using milliard.[/color]
>
> I will continue to use "billion" for 1e12 and "milliard" for 1e9, and if
> people wish to misunderstand me, that is their problem, not mine.
>
>[color=green]
>> [...] President^WPM Blair isn't helping.[/color]
>
> Don't blame me. I didn't vote for him. (Ever.)[/color]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#define BUF_MAX 80
int main (void) {
char buf[BUF_MAX];
unsigned long l, i, *dynarray;
size_t s;
printf("give me a number less than a third billion: \n");
while(fgets(buf, BUF_MAX, stdin) != NULL) {
if ((s = strspn(buf, "0123456789 \t\n")) == strlen(buf)) {
errno = 0;
l = strtoul(buf, NULL, 10);
if (errno == ERANGE) {
printf("number out of range!\n");
} else {
/* dyn mem alloc */
dynarray = malloc((l+1) * sizeof *dynarray);
if (dynarray != NULL)
{
/* populate array with the dummy's index */
for(i = 0;i <= l; ++ i) dynarray[i] = i;
/* output: print em all */
for(i = 0;i <= l; ++ i)
{
/* printf("%lu %lu\n", i, l); */
}
free(dynarray);
}
/* else code for unsuccessful malloc here */
else
{
printf("malloc failed\n");
free(dynarray);
}
}
} else {
while(s--)
putchar(' ');
putchar('^');
printf(" invalid character\n");
}
}
return 0;
}
/* end source */
This is probably most directed at Mr. Mair, yet I wanted to comment on a
couple things said along the way and thought the better way to do that might
be to do it in one morningly post. Between an ell at 50 million and 60
million, the malloc fails on my 'puter. On the else branch, I still free
it, yet my unnamed OS doesn't seem to be the same after the malloc fails. I
have warnings set as high as I know how to put them and get none.
As to the language stuff, it's always been said that England and the US were
two countries separated by a language. After listening to Southern Neocon
Repugs for a seeming eternity, the split is much deeper than that.
Cbfalconer is exactly correct. If there is the chance of miscommunication,
show the exponent. I'm unaware of what a Standard date would look like, but
I always am wary of order in date and month when corresponding with
Continentals. Precise communication in clc, unlike the constant stream of
Kremlinized crap that flows out of our largest bully pulpit is, as they say,
impordint. Joe | | | | re: dynamic mem alloc q
"Joe Smith" <grumpy196884@netzero.net> writes:
[...][color=blue]
> As to the language stuff, it's always been said that England and the US were
> two countries separated by a language. After listening to Southern Neocon
> Repugs for a seeming eternity, the split is much deeper than that.
> Cbfalconer is exactly correct. If there is the chance of miscommunication,
> show the exponent. I'm unaware of what a Standard date would look like, but
> I always am wary of order in date and month when corresponding with
> Continentals. Precise communication in clc, unlike the constant stream of
> Kremlinized crap that flows out of our largest bully pulpit is, as they say,
> impordint. Joe[/color]
I suggest that national politics, or even international politics, is
not a good subject for comp.lang.c. I have my own very strong
opinions in those areas, but I don't express them, or even allude to
them, here in comp.lang.c. The very last thing we need here is a
flame war about, say, US party politics.
But the real reason I'm posting this followup is to answer your
question about standard date formats. There is an ISO standard for
time and date formats, ISO 8601. The date format is YYYY-MM-DD, where
YYYY is the year, MM is the month (01..12), and DD is the day of the
month (01..31). It's unambiguous, it sorts correctly, and it's not
subject to variations in natural-language month names. For example,
today is 2006-05-11.
For more details, see <http://www.cl.cam.ac.uk/~mgk25/iso-time.html>.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. | | | | re: dynamic mem alloc q
Richard Heathfield wrote:[color=blue]
> Richard Bos said:
>[color=green]
> > "Joe Smith" <grumpy196884@netzero.net> wrote:
> >[color=darkred]
> >> I would object to my witticism needing to be regarded as a string literal
> >> had the grammar been correct. Maybe we should say something, as I have
> >> serially witnessed German-English discussions fly off the rails right
> >> here,
> >> usually by the English speaker thinking 'Milliard' was a million. I will
> >> use billion to mean 10^9 and trillion to mean 10^12 .[/color]
> >
> > Ah, but _that_, OTOH, has the disadvantage that you're only compatible
> > with USAnians and USAnianised[1] Britons[2].[/color]
>
> And, apparently, the French.
>
> "Milliard" is, of course, the proper way to describe 1,000,000,000.[/color]
The english got the 'proper' use of billion from the French after the
17th century, apparently. The french mathematicians changed the group
of six digits to represent multiples of millions to groups of three
digits, a little later. US adopted the French system, but the French
switched back, again, to the old system, later. The English switched to
the US system afterwards. Supposedly the american use of billion was
more practical (at least in that period). There was also some story
related to the City of Ilion (Troy) but I forgot it :-).
I've been away from the group for some time. It's good to be back! :-)
--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...) | | | | re: dynamic mem alloc q
"Keith Thompson"[color=blue]
> "Joe Smith" <grumpy196884@netzero.net> writes:
> [...][color=green]
>> [arguably inflammatory rhetoric intermixed with something topical][/color][/color]
[color=blue]
> I suggest that national politics, or even international politics, is
> not a good subject for comp.lang.c. I have my own very strong
> opinions in those areas, but I don't express them, or even allude to
> them, here in comp.lang.c. The very last thing we need here is a
> flame war about, say, US party politics.
>
> But the real reason I'm posting this followup is to answer your
> question about standard date formats. There is an ISO standard for
> time and date formats, ISO 8601. The date format is YYYY-MM-DD, where
> YYYY is the year, MM is the month (01..12), and DD is the day of the
> month (01..31). It's unambiguous, it sorts correctly, and it's not
> subject to variations in natural-language month names. For example,
> today is 2006-05-11.[/color]
Politics qua politics is OT. I wanted to state on 2006-05-12 that this
isn't a good day for US programmers from a perspective of resource
allocation. Think, Keith, of all the stuff you have to do to get your
projects staffed and done. The US taxpayer now owns the largest piece of
digital duke ever instantiated. Data mining? Is that for hobbits? The army
of persons who have been sniffing packets needed to get
UP_CLOSE_AND_PERSONAL, for which they appear to lack either courage, or more
likely, conviction, and certainly, court approval. Did we really need to
invest these type of resources in other snafu? I'll try to focus again on
memory management techniques in the C programming language. Joe | | | | re: dynamic mem alloc q
"Joe Smith" <grumpy196884@netzero.net> writes:[color=blue]
> "Keith Thompson"[color=green]
>> "Joe Smith" <grumpy196884@netzero.net> writes:
>> [...][color=darkred]
>>> [arguably inflammatory rhetoric intermixed with something topical][/color][/color]
>[color=green]
>> I suggest that national politics, or even international politics, is
>> not a good subject for comp.lang.c. I have my own very strong
>> opinions in those areas, but I don't express them, or even allude to
>> them, here in comp.lang.c. The very last thing we need here is a
>> flame war about, say, US party politics.[/color][/color]
[snip][color=blue]
>
> Politics qua politics is OT. I wanted to state on 2006-05-12 that this
> isn't a good day for US programmers from a perspective of resource
> allocation. Think, Keith, of all the stuff you have to do to get your
> projects staffed and done. The US taxpayer now owns the largest piece of
> digital duke ever instantiated. Data mining? Is that for hobbits? The army
> of persons who have been sniffing packets needed to get
> UP_CLOSE_AND_PERSONAL, for which they appear to lack either courage, or more
> likely, conviction, and certainly, court approval. Did we really need to
> invest these type of resources in other snafu? I'll try to focus again on
> memory management techniques in the C programming language. Joe[/color]
None of this is relevant to the C programming language.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,374 network members.
|