Sunday, March 28, 2010

comp.lang.c - 10 new messages in 6 topics - digest

comp.lang.c
http://groups.google.com/group/comp.lang.c?hl=en

comp.lang.c@googlegroups.com

Today's topics:

* Container library (continued) - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/3763649cc890efcc?hl=en
* Questions about argv - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/5eb85a70a33b446c?hl=en
* metaprogramming with the preprocessor: when is it too much? (inspired by the
iterators thread) - 2 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/590347e0095ab306?hl=en
* How should I test for a null pointer? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/ac6fdf22358cde1a?hl=en
* nothing much - 1 messages, 1 author
http://groups.google.com/group/comp.lang.c/t/3040e7c069dc5b93?hl=en
* The answer is "All of it." of course. - 3 messages, 2 authors
http://groups.google.com/group/comp.lang.c/t/3a070a9762275cee?hl=en

==============================================================================
TOPIC: Container library (continued)
http://groups.google.com/group/comp.lang.c/t/3763649cc890efcc?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Mar 27 2010 10:18 pm
From: "ng2010"


Nick Keighley wrote:
> On 17 Mar, 04:22, "ng2010" <ng2...@att.invalid> wrote:
>> So sad to be dying and seeing youth tackling problems already solved
>> in my own youth.
>
> and the solution was? I'm not convinced there *is* a single right
> answer for all situations.

Stating the obvious does not make you wise (you owe me now for I am your
teacher). I want money.

Else, shut up.

==============================================================================
TOPIC: Questions about argv
http://groups.google.com/group/comp.lang.c/t/5eb85a70a33b446c?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Mar 27 2010 10:28 pm
From: Michael Tsang


WD wrote:


> main(x,y)
> {

This is illegal. What do you mean?

You want

int main(int x, char **y)

?


== 2 of 2 ==
Date: Sat, Mar 27 2010 11:15 pm
From: Barry Schwarz


On Sat, 27 Mar 2010 13:08:37 -0700 (PDT), WD <liamymail@yahoo.com>
wrote:

>I have a few questions regarding argv. When passing command-line
>arguments to a C program, I understand that argc (int argc) is the
>number of command-line arguments with which the program was invoked,
>and argv (char *argv[]) is a pointer to an array of character strings
>that contain the arguments, one per string. Why does the code
>illustrated below work as written on i386 using Watcom C on Windows XP
>and probably also using gcc on Linux as well?

Because it invokes undefined behavior. One of the worst
manifestations of undefined behavior is to do what you expect (this
time).

>
>#include <stdio.h>
>
>main(x,y)

Under C89, y will have type int. The actual argument is type char*.

>{
> printf("%s\n",*(int *)y);

The format specification %s requires the corresponding argument to
have type char*. This argument has type int. Some compilers will
check and diagnose this error.

> if (x>1)
> {
> y =y+4;

You were unlucky that sizeof(char*) is 4.

> printf("%s\n",*(int *)y);

Same argument mismatch.

> }
>}
>
>A few questions come to mind:
>
>1.Does the compiler automatically assume main(x,y) to really mean
>main(int x, char *y[]) ?

No.

>2.How does the first *(int *)y refer to y[0] (the first command-line
>argument, i.e. the name of the program) ?

It doesn't.

>3.After y=y+4 why does the second *(int *)y now refer to y[1] (i.e.
>the second command -line argument?

It doesn't.

--
Remove del for email

==============================================================================
TOPIC: metaprogramming with the preprocessor: when is it too much? (inspired
by the iterators thread)
http://groups.google.com/group/comp.lang.c/t/590347e0095ab306?hl=en
==============================================================================

== 1 of 2 ==
Date: Sat, Mar 27 2010 10:41 pm
From: "io_x"

"Mark Piffer" <mark.piffer@chello.at> ha scritto nel messaggio
news:4aaa2413-695f-4786-bf6e-f90c9b70cc0b@k19g2000yqn.googlegroups.com...
> Hi c.l.c,

i prefer rewrite code, to debug code full of macro like what you show.

For me the only macro in C that allow to debug
could be only "#define name numberOrName"


== 2 of 2 ==
Date: Sat, Mar 27 2010 10:46 pm
From: "io_x"

"Mark Piffer" <mark.piffer@chello.at> ha scritto nel messaggio
news:4aaa2413-695f-4786-bf6e-f90c9b70cc0b@k19g2000yqn.googlegroups.com...
> Hi c.l.c,

i prefer rewrite code, to debug code full of macro like what you show.

For me the only macro in C that allow to debug
could be only "#define name numberOrName"


==============================================================================
TOPIC: How should I test for a null pointer?
http://groups.google.com/group/comp.lang.c/t/ac6fdf22358cde1a?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Mar 27 2010 10:41 pm
From: "io_x"


"Eric Sosman" ha scritto nel messaggio
news:hoagea$fed$1@news.eternal-september.org...
> Off-topic (but on-thread) reminiscence: I once wrote assembly
> code for a machine, using the abbreviation "SP" quite a lot -- and
> it didn't mean "Stack Pointer." Anyone care to guess?

i use all "esp", "sp", "s", "" because some macro definition

==============================================================================
TOPIC: nothing much
http://groups.google.com/group/comp.lang.c/t/3040e7c069dc5b93?hl=en
==============================================================================

== 1 of 1 ==
Date: Sat, Mar 27 2010 10:37 pm
From: Phred Phungus


Seebs wrote:
> On 2010-03-23, Phred Phungus <Phred@example.invalid> wrote:
>> 1 implementation-defined behavior
>> unspecified behavior where each implementation documents how the
>> choice is made. EXAMPLE An example of implementation-defined behavior
>> is the propagation of the high-order bit when a signed integer is
>> shifted right.
>
>> So, if an implementation *doesn't* document how propagation occurs in
>> the above example, is the behavior just unspecified or does it get
>> bumped to undefined, as non-entities are?
>
> Neither. In that case, the implementation is broken, and does not conform
> to the standard.

Broken? How about imperfect?
--
fred

==============================================================================
TOPIC: The answer is "All of it." of course.
http://groups.google.com/group/comp.lang.c/t/3a070a9762275cee?hl=en
==============================================================================

== 1 of 3 ==
Date: Sat, Mar 27 2010 10:46 pm
From: Phred Phungus


Dr Malcolm McLean wrote:

[broadening x-post to sci.math]

> On 27 Mar, 13:35, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>> What makes you think that (RAND_MAX + 1) is defined?
>>
>> And what makes him think that rand()*rand() has a
>> binomial distribution, even if it doesn't overflow?
>>
> I nodded.
> A web search turns up that there's no neat way of obtaining the
> probability density function of a the product of several uniformly-
> distributed random variables. Basically you have to go to log space
> and treat is as a sum (which approximates the normal distribution as N
> increases).
>
>

I'm reading this in comp.lang.c, and I don't think we have the firepower
to determine this distribution, hence the crosspost.

Hello sci.math. If rand has a flat pdf on the interval [0, 32768], what
is the distribution of rand squared?

Thanks for your comment, and cheers,
--
fred


== 2 of 3 ==
Date: Sat, Mar 27 2010 11:05 pm
From: Ray Vickson


On Mar 27, 10:46 pm, Phred Phungus <Ph...@example.invalid> wrote:
> Dr Malcolm McLean wrote:
>
> [broadening x-post to sci.math]
>
> > On 27 Mar, 13:35, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> >> What makes you think that (RAND_MAX + 1) is defined?
>
> >>      And what makes him think that rand()*rand() has a
> >> binomial distribution, even if it doesn't overflow?
>
> > I nodded.
> > A web search turns up that there's no neat way of obtaining the
> > probability density function of a the product of several uniformly-
> > distributed random variables. Basically you have to go to log space
> > and treat is as a sum (which approximates the normal distribution as N
> > increases).
>
> I'm reading this in comp.lang.c, and I don't think we have the firepower
> to determine this distribution, hence the crosspost.
>
> Hello sci.math.  If rand has a flat pdf on the interval [0, 32768], what
> is the distribution of rand squared?
>
> Thanks for your comment, and cheers,
> --
> fred

If U is uniformly distributed on interval [0,M], then U^2 will be
distributed on interval [0,M^2]. Find the distribution as follows: for
any x in (0,M^2) the cumulative distribution of U^2 is F(x) = Pr{U^2
<= x} = Pr{U <= sqrt(x)}; we don't have negative values of U, so we
don't consider the interval from -sqrt(x) to 0. Anyway, for uniform U
on [0,M], Pr{U <= y} = y/M for y in [0,M]. For y = sqrt(x) this gives
Pr{U^2 <= x} = sqrt(x)/M [note: the right-hand-side = 1 when x = M^2,
as it should]. Thus, the density function of U^2 is f(x) = dF(x)/dx =
(1/2)/[M*sqrt(x)].

Note: this assumes continuously-distributed uniform U. For an *actual*
rand, U will be discrete. Furthermore, for a typical congruential
generator, the value 0 is never attained, and the distribution will be
slightly non-uniform over the other values 1, 2, ..., 32768.

R.G. Vickson


== 3 of 3 ==
Date: Sun, Mar 28 2010 12:00 am
From: Phred Phungus


Ray Vickson wrote:
> On Mar 27, 10:46 pm, Phred Phungus <Ph...@example.invalid> wrote:
>> Dr Malcolm McLean wrote:
>>
>> [broadening x-post to sci.math]

>> Hello sci.math. If rand has a flat pdf on the interval [0, 32768], what
>> is the distribution of rand squared?

> If U is uniformly distributed on interval [0,M], then U^2 will be
> distributed on interval [0,M^2]. Find the distribution as follows: for
> any x in (0,M^2) the cumulative distribution of U^2 is F(x) = Pr{U^2
> <= x} = Pr{U <= sqrt(x)}; we don't have negative values of U, so we
> don't consider the interval from -sqrt(x) to 0. Anyway, for uniform U
> on [0,M], Pr{U <= y} = y/M for y in [0,M]. For y = sqrt(x) this gives
> Pr{U^2 <= x} = sqrt(x)/M [note: the right-hand-side = 1 when x = M^2,
> as it should]. Thus, the density function of U^2 is f(x) = dF(x)/dx =
> (1/2)/[M*sqrt(x)].

Ok. So, if one is to verify, then you're gonna heat up the
pseudorandoms and have M^2 bins. If the product of r = rand() and s =
rand() equals q, then bin number q, initially set to zero, increments.

q2) Does anyone have a statistical model for this event being
pseudorandom as opposed to being clunky in the lower bits?
>
> Note: this assumes continuously-distributed uniform U. For an *actual*
> rand, U will be discrete. Furthermore, for a typical congruential
> generator, the value 0 is never attained, and the distribution will be
> slightly non-uniform over the other values 1, 2, ..., 32768.

Thanks so much for your comment and your minor bounds error above like
the one I made. For clarity's sake, I should stipulate that the
interval is closed about zero and a value stipulated by the C
implementation. I'd like to choose this as [0, 32767] because then I
know I won't be in any trouble with M^2.

q3) How different is the analysis when it goes from continuous to discrete?
--
fred


==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.c"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.c?hl=en

To unsubscribe from this group, send email to comp.lang.c+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.c/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate