Connecting Tech Pros Worldwide Help | Site Map

Help with sizeof and pointers

  #1  
Old July 19th, 2005, 06:27 PM
Metzen
Guest
 
Posts: n/a
hello,
ok, I want to find the length of an int array that is being passed to a function:

main()
{
int array[]={1,2,3,4,5,6,7,8};
function(array);
}
function(int *array)
{
int arraylen = sizeof(*array)/sizeof(int);
}


arraylen should be 8 I get 1.

What am I doing Wrong?

Thanx
  #2  
Old July 19th, 2005, 06:27 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Metzen wrote:[color=blue]
> hello,
> ok, I want to find the length of an int array that is being passed to a function:[/color]

You can't pass an array to a function, at least not directly.
[color=blue]
>
> main()[/color]

int main()

There is no "implicit int" rule in C++, and there hasn't been for many
years.
[color=blue]
> {
> int array[]={1,2,3,4,5,6,7,8};
> function(array);[/color]

This passes a pointer to the function.
[color=blue]
> }
> function(int *array)[/color]

'array' is a somewhat misleading name for a pointer.
[color=blue]
> {
> int arraylen = sizeof(*array)/sizeof(int);[/color]

sizeof(*array) == sizeof(int), so of course you get 1 here. But no
matter what you do, you won't get the size of the memory pointed to by
'array' using sizeof.
[color=blue]
> }
>
>
> arraylen should be 8 I get 1.
>
> What am I doing Wrong?[/color]

You need to pass the size into the function.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #3  
Old July 19th, 2005, 06:27 PM
Steven C.
Guest
 
Posts: n/a

re: Help with sizeof and pointers


You have two choices either end your array with a unque int or pass the
size.

main()
{
int array[]={1,2,3,4,5,6,7,8};
function (array, sizeof(array)/sizeof(int))
}

function(int *array, int size)
{
}



"Metzen" <aniled@yahoo.com> wrote in message
news:4e629682.0309121725.2407d28d@posting.google.c om...
hello,
ok, I want to find the length of an int array that is being passed to a
function:

main()
{
int array[]={1,2,3,4,5,6,7,8};
function(array);
}
function(int *array)
{
int arraylen = sizeof(*array)/sizeof(int);
}


arraylen should be 8 I get 1.

What am I doing Wrong?

Thanx


  #4  
Old July 19th, 2005, 06:27 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Steven C. wrote:
[color=blue]
> You have two choices[/color]

Please don't top-post. Re-read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #5  
Old July 19th, 2005, 06:28 PM
Jon Bell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


In article <4e629682.0309121725.2407d28d@posting.google.com >,
Metzen <aniled@yahoo.com> wrote:[color=blue]
>hello,
>ok, I want to find the length of an int array that is being passed to a
>function:[/color]

You can't. You have to pass in the length as a separate
argument/parameter.
[color=blue]
>main()
>{
>int array[]={1,2,3,4,5,6,7,8};
>function(array);
>}
>function(int *array)
>{
>int arraylen = sizeof(*array)/sizeof(int);
>}
>
>
>arraylen should be 8 I get 1.
>
>What am I doing Wrong?[/color]

You're using arrays instead of vectors.

#include <vector>

using namespace std;

void function (vector<int>& array)) // functions in C++ must have
// return types
{
int arraylen = array.size();
}

int main () // according to the C++ standard, main() must return an int.
{
vector<int> array(8);
array[0] = 1;
array[1] = 2;
// etc.
function (array);
return 0;
}

--
Jon Bell <jtbellap8@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
  #6  
Old July 19th, 2005, 06:28 PM
Julián Albo
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Metzen escribió:
[color=blue]
> ok, I want to find the length of an int array that is being passed to afunction:
>
> main()
> {
> int array[]={1,2,3,4,5,6,7,8};
> function(array);
> }
> function(int *array)
> {
> int arraylen = sizeof(*array)/sizeof(int);
> }
>
> arraylen should be 8 I get 1.
>
> What am I doing Wrong?[/color]

You are using sizeof (*array), * array is equivalent in this case to
array [0], that is, an int, then you are dividing sizeof (int) by sizeof
(int).

You need something like sizeof (array) / sizeof (int), if what you
intend is obtain the number of elements in the array. Or better yet,
sizeof (array) / sizeof (* array), that will no require change if you
later change your mind and use an array of double, for example.

Regards.
  #7  
Old July 19th, 2005, 06:28 PM
Big Brian
Guest
 
Posts: n/a

re: Help with sizeof and pointers


> You need to pass the size into the function.


Or, if you can make some assumptions about the array, like what's the
last value in it ( like '\0' terminated c style char arrays ), you can
determine the length of the array.

-Brian
  #8  
Old July 19th, 2005, 06:28 PM
Julián Albo
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Julián Albo escribió:
[color=blue][color=green]
> > main()
> > {
> > int array[]={1,2,3,4,5,6,7,8};
> > function(array);
> > }
> > function(int *array)
> > {
> > int arraylen = sizeof(*array)/sizeof(int);
> > }
> >
> > arraylen should be 8 I get 1.
> >
> > What am I doing Wrong?[/color]
>
> You are using sizeof (*array), * array is equivalent in this case to
> array [0], that is, an int, then you are dividing sizeof (int) by sizeof
> (int).
>
> You need something like sizeof (array) / sizeof (int), if what you
> intend is obtain the number of elements in the array. Or better yet,
> sizeof (array) / sizeof (* array), that will no require change if you
> later change your mind and use an array of double, for example.[/color]

Ops, I don't see you passed array to a function. In that case sizeof
array will give you the size of a pointer, not the size of the array.

Regards.
  #9  
Old July 19th, 2005, 06:28 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers


"Metzen" <aniled@yahoo.com> wrote[color=blue]
> hello,
> ok, I want to find the length of an int array that is being passed to a[/color]
function:

The following might work. I can't work out whether the standard says it does.

// Begin listing
#include <iostream>
#include <ostream>

#define MACRO(a) (sizeof (a) / sizeof (int))

template <typename T, unsigned N>
int function (T (&) [N]) { return N; }

int test (int a [])
{
// std::cout << function (a) << ", "; // compile-time error
std::cout << MACRO (a) << std::endl; // no error signaled
}

int main ()
{
int array [] = { 1, 2, 3, 4, 5, 6, 7, 8 };

std::cout << function (array) << ", ";
std::cout << MACRO (array) << std::endl;

test (array);
}
// End listing

I get what I expected on mingw32-g++ 3.2 and on bcb32:
the output is "8, 8"; "1". Both compilers report the compile
time error marked if I uncomment that line.

So the template version is slightly superior in that, although
it only works in a small set of situations, it will not compile
unless it can give you the correct answer.

It's probably only rarely that this can be used instead of the
techniques mentioned in the other replies, and even more
rarely that it will provide any significant advantage in speed
or code size. But maybe sometimes.

Yours,
Buster.


  #10  
Old July 19th, 2005, 06:28 PM
Shane Beasley
Guest
 
Posts: n/a

re: Help with sizeof and pointers


aniled@yahoo.com (Metzen) wrote in message news:<4e629682.0309121725.2407d28d@posting.google. com>...
[color=blue]
> function(int *array)
> {
> int arraylen = sizeof(*array)/sizeof(int);[/color]

That's the size of a pointer divided by the size of the object to
which it points, the result of which is meaningless.
[color=blue]
> }
>
>
> arraylen should be 8 I get 1.
>
> What am I doing Wrong?[/color]

You're passing a pointer, not an array. Technically, in modern C++,
you can fix the problem by passing an array by reference like this:

#include <cstddef>

// the size of an array is most properly represented by std::size_t
template <std::size_t N>
void function (int (&array) [N]) {
std::size_t arraylen = N;
}

However, that most people don't write functions like this. Rather,
they just pass in the size themselves:

void function (int *array, std::size_t arraylen) { }
function(array, sizeof(array) / sizeof(array[0]));

Perhaps you can combine the approaches:

template <typename T, std::size_t N>
std::size_t size (T (&) [N]) { return N; }
template <typename T, std::size_t N>
std::size_t size (const T (&) [N]) { return N; }
function(array, size(array));

- Shane
  #11  
Old July 19th, 2005, 06:28 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers



"Buster" <noone@nowhere.com> wrote[color=blue]
> #define MACRO(a) (sizeof (a) / sizeof (int))[/color]

Or better,
#define MACRO(a) (sizeof (a) / sizeof * (a))

Regards.


  #12  
Old July 19th, 2005, 06:28 PM
Duane Hebert
Guest
 
Posts: n/a

re: Help with sizeof and pointers


> // Begin listing[color=blue]
> #include <iostream>
> #include <ostream>
>
> #define MACRO(a) (sizeof (a) / sizeof (int))
>
> template <typename T, unsigned N>
> int function (T (&) [N]) { return N; }
>
> int test (int a [])
> {
> // std::cout << function (a) << ", "; // compile-time error
> std::cout << MACRO (a) << std::endl; // no error signaled
> }
>
> int main ()
> {
> int array [] = { 1, 2, 3, 4, 5, 6, 7, 8 };
>
> std::cout << function (array) << ", ";
> std::cout << MACRO (array) << std::endl;
>
> test (array);
> }
> // End listing
>
> I get what I expected on mingw32-g++ 3.2 and on bcb32:
> the output is "8, 8"; "1". Both compilers report the compile
> time error marked if I uncomment that line.
>
> So the template version is slightly superior in that, although
> it only works in a small set of situations, it will not compile
> unless it can give you the correct answer.
>
> It's probably only rarely that this can be used instead of the
> techniques mentioned in the other replies, and even more
> rarely that it will provide any significant advantage in speed
> or code size. But maybe sometimes.[/color]



What happens if you do:
int main ()
{
short array [] = { 1, 2, 3, 4, 5, 6, 7, 8 };
std::cout << MACRO (array) << std::endl;
}

What if short was SomeLargeObect instead? Stroustrup advises against using
macros as they defeat the
type safety that C++ supplies. I would suggest that the template solution
is more than "slightly" superior in
that respect.


  #13  
Old July 19th, 2005, 06:28 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Big Brian wrote:
[color=blue][color=green]
>>You need to pass the size into the function.[/color]
>
>
>
> Or, if you can make some assumptions about the array, like what's the
> last value in it ( like '\0' terminated c style char arrays ), you can
> determine the length of the array.[/color]

True. That's sort of passing the size in implicitly. Passing a
std::vector (probably by reference) instead is another obvious solution,
which I didn't mention mostly because I was in a hurry. But that also
passes the size (implicitly) into the function. My statement is quite
true, but has to be taken in a very broad sense. Somehow, information
about where the array ends must be communicated to the function (and
it's not implicit in an "array argument" which is, in fact, not an array
at all).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #14  
Old July 19th, 2005, 06:28 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Buster wrote:
[color=blue]
> "Metzen" <aniled@yahoo.com> wrote
>[color=green]
>>hello,
>>ok, I want to find the length of an int array that is being passed to a[/color]
>
> function:
>
> The following might work. I can't work out whether the standard says it does.[/color]

It absolutely will not work.
[color=blue]
>
> // Begin listing
> #include <iostream>
> #include <ostream>
>
> #define MACRO(a) (sizeof (a) / sizeof (int))
>
> template <typename T, unsigned N>
> int function (T (&) [N]) { return N; }
>
> int test (int a [])[/color]

The type of a is 'pointer to int'.
[color=blue]
> {
> // std::cout << function (a) << ", "; // compile-time error[/color]

This didn't work because 'a' is not an array, but a pointer. You CANNOT
pass arrays to functions (directly). It always passes a pointer. Array
arguments... aren't. They are pointer arguments.
[color=blue]
> std::cout << MACRO (a) << std::endl; // no error signaled[/color]

The macro expands to

(sizeof (a) / sizeof (int))

which is equivalent to (sizeof(int*)/sizeof(int)) which does not give
the number of elements pointed to by 'a'.

I see that later you say this is the result you expected. OK, then...
but it's not an answer to the question, because it doesn't let you
determine the size of an array pointed to by a pointer argument to a
function.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #15  
Old July 19th, 2005, 06:28 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers


"Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote in message[color=blue]
> Buster wrote:[color=green]
> > The following might work. I can't work out whether the standard says it[/color][/color]
does.[color=blue]
>
> It absolutely will not work.[/color]

I think we're in agreement about what does and doesn't work. What I expected
to happen, happens. What I'm not sure of is whether what I expect is enforced
by the standard.
[color=blue][color=green]
> > // std::cout << function (a) << ", "; // compile-time error[/color]
>
> This didn't work because 'a' is not an array, but a pointer. You CANNOT
> pass arrays to functions (directly). It always passes a pointer. Array
> arguments... aren't. They are pointer arguments.[/color]

Yes, I know.
[color=blue][color=green]
> > std::cout << MACRO (a) << std::endl; // no error signaled[/color]
>
> The macro expands to
>
> (sizeof (a) / sizeof (int))
>
> which is equivalent to (sizeof(int*)/sizeof(int)) which does not give
> the number of elements pointed to by 'a'.[/color]

Yes, I know. I recommended the template solution and showed
the older C-style technique for comparison. It's unfortunate that
I got the macro wrong, but there you go.
[color=blue]
> I see that later you say this is the result you expected. OK, then...
> but it's not an answer to the question, because it doesn't let you
> determine the size of an array pointed to by a pointer argument to a
> function.[/color]

The question was "I want to find the length of an int array that is being
passed to a function". No mention of pointers there.
[color=blue]
> -Kevin[/color]


  #16  
Old July 19th, 2005, 06:28 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers



"Duane Hebert" <spoo@flarn.com> wrote
[color=blue]
> What happens if you do:
> int main ()
> {
> short array [] = { 1, 2, 3, 4, 5, 6, 7, 8 };
> std::cout << MACRO (array) << std::endl;
> }[/color]

Implementation specific. But I should have had:
#define MACRO(a) (sizeof (a) / sizeof * (a))
which works in that situation.
[color=blue]
> What if short was SomeLargeObect instead?[/color]

The new MACRO would work just fine.
[color=blue]
> Stroustrup advises against using
> macros as they defeat the
> type safety that C++ supplies.[/color]

Quite right too, but type safety is not the issue here.
The decay of an array into a pointer is what makes
this macro dangerous.
[color=blue]
> I would suggest that the template solution
> is more than "slightly" superior in
> that respect.[/color]

"Slightly" is enough for me.

Thanks,
Buster.


  #17  
Old July 19th, 2005, 06:29 PM
Artie Gold
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Buster wrote:[color=blue]
> "Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote in message
>[color=green]
>>Buster wrote:
>>[color=darkred]
>>>The following might work. I can't work out whether the standard says it[/color]
>>[/color]
> does.
>[color=green]
>>It absolutely will not work.[/color]
>
>
> I think we're in agreement about what does and doesn't work. What I expected
> to happen, happens. What I'm not sure of is whether what I expect is enforced
> by the standard.
>
>[color=green][color=darkred]
>>>// std::cout << function (a) << ", "; // compile-time error[/color]
>>
>>This didn't work because 'a' is not an array, but a pointer. You CANNOT
>>pass arrays to functions (directly). It always passes a pointer. Array
>>arguments... aren't. They are pointer arguments.[/color]
>
>
> Yes, I know.
>
>[color=green][color=darkred]
>>> std::cout << MACRO (a) << std::endl; // no error signaled[/color]
>>
>>The macro expands to
>>
>>(sizeof (a) / sizeof (int))
>>
>>which is equivalent to (sizeof(int*)/sizeof(int)) which does not give
>>the number of elements pointed to by 'a'.[/color]
>
>
> Yes, I know. I recommended the template solution and showed
> the older C-style technique for comparison. It's unfortunate that
> I got the macro wrong, but there you go.
>
>[color=green]
>>I see that later you say this is the result you expected. OK, then...
>>but it's not an answer to the question, because it doesn't let you
>>determine the size of an array pointed to by a pointer argument to a
>>function.[/color]
>
>
> The question was "I want to find the length of an int array that is being
> passed to a function". No mention of pointers there.
>[/color]
You may be passing an array, but by the time the function you're
calling sees it, it has decayed into a pointer.

HTH,
--ag


--
Artie Gold -- Austin, Texas

  #18  
Old July 19th, 2005, 06:29 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers


> > The question was "I want to find the length of an int array that is being[color=blue][color=green]
> > passed to a function". No mention of pointers there.
> >[/color]
> You may be passing an array, but by the time the function you're
> calling sees it, it has decayed into a pointer.[/color]


Not if you pass the array by reference.

Regards,
Buster.


  #19  
Old July 19th, 2005, 06:29 PM
Artie Gold
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Buster wrote:[color=blue][color=green][color=darkred]
>>>The question was "I want to find the length of an int array that is being
>>>passed to a function". No mention of pointers there.
>>>[/color]
>>
>>You may be passing an array, but by the time the function you're
>>calling sees it, it has decayed into a pointer.[/color]
>
>
>
> Not if you pass the array by reference.
>[/color]

OK, I'm intrigued.
Example code?

Cheers,
--ag

--
Artie Gold -- Austin, Texas

  #20  
Old July 19th, 2005, 06:29 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers


"Artie Gold" <artiegold@austin.rr.com> wrote[color=blue][color=green][color=darkred]
> >>You may be passing an array, but by the time the function you're
> >>calling sees it, it has decayed into a pointer.[/color]
> >
> > Not if you pass the array by reference.[/color]
>
> OK, I'm intrigued.
> Example code?[/color]

I already posted some. Shane Beasley's post has examples too.

Yours,
Buster.


  #21  
Old July 19th, 2005, 06:29 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Buster wrote:
[color=blue]
> "Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote in message
>[color=green]
>>It absolutely will not work.[/color]
>
>
> I think we're in agreement about what does and doesn't work. What I expected
> to happen, happens. What I'm not sure of is whether what I expect is enforced
> by the standard.[/color]

I should have removed that line from my post when I realized what you
were doing.
[color=blue]
>
>
> The question was "I want to find the length of an int array that is being
> passed to a function". No mention of pointers there.
>[/color]

But an array cannot be (directly) passed to a function. I think the
template and/or reference solution seems unlikely to work well in
practice. When dealing with "arrays", one often actually deals with
pointers (because it was passed from elsewhere, or dynamically allocated).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #22  
Old July 19th, 2005, 06:29 PM
Artie Gold
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Buster wrote:[color=blue]
> "Artie Gold" <artiegold@austin.rr.com> wrote
>[color=green][color=darkred]
>>>>You may be passing an array, but by the time the function you're
>>>>calling sees it, it has decayed into a pointer.
>>>
>>>Not if you pass the array by reference.[/color]
>>
>>OK, I'm intrigued.
>>Example code?[/color]
>
>
> I already posted some. Shane Beasley's post has examples too.
>[/color]
Unless I'm missing something (not terribly unlikely), all the
examples provided only work when the actual array is in scope
at the point where its size is being asked (which means that
the size would be known anyway).

BTW - there's no flame intended here at all.

Cheers,
--ag

--
Artie Gold -- Austin, Texas

  #23  
Old July 19th, 2005, 06:29 PM
Duane Hebert
Guest
 
Posts: n/a

re: Help with sizeof and pointers


> > What happens if you do:[color=blue][color=green]
> > int main ()
> > {
> > short array [] = { 1, 2, 3, 4, 5, 6, 7, 8 };
> > std::cout << MACRO (array) << std::endl;
> > }[/color]
>
> Implementation specific. But I should have had:
> #define MACRO(a) (sizeof (a) / sizeof * (a))
> which works in that situation.[/color]

I'm curious. Why not just use std::vector<int>?


  #24  
Old July 19th, 2005, 06:29 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers



"Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote
[color=blue][color=green]
> > The question was "I want to find the length of an int array that is being
> > passed to a function". No mention of pointers there.
> >[/color]
> But an array cannot be (directly) passed to a function.[/color]

You've got me there. Indirection is required, although in this case
it's penalty-free and pretty much a syntactic thing.
[color=blue]
> I think the
> template and/or reference solution seems unlikely to work well in
> practice. When dealing with "arrays", one often actually deals with
> pointers (because it was passed from elsewhere, or dynamically allocated).[/color]

Agreed, with reservations. The template I gave (or one of Shane's) works
when it works and doesn't do any harm.

IIRC, reference-to-array function parameters are not well supported on
certain compilers (*cough* borland) and can decay into a pointer to the
first element. That's another reason to be careful with them.

Regards,
Buster


  #25  
Old July 19th, 2005, 06:29 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers


"Duane Hebert" <spoo@flarn.com> wrote[color=blue]
> I'm curious. Why not just use std::vector<int>?[/color]

I don't recall mentioning vector. Go with it if it
does what you need.

Good luck,
Buster.


  #26  
Old July 19th, 2005, 06:29 PM
Buster
Guest
 
Posts: n/a

re: Help with sizeof and pointers



"Artie Gold" <artiegold@austin.rr.com> wrote[color=blue]
> Unless I'm missing something (not terribly unlikely), all the
> examples provided only work when the actual array is in scope
> at the point where its size is being asked (which means that
> the size would be known anyway).[/color]

No, you're quite right. As others have said, it's not terribly useful.
But I have found something like the following handy in the past, to
save a little typing.

template <typename U, typename V, std::size_t N>
U (& u) [N] add (U (& u) [N], V (& v) [N])
{
for (std::size_t i = 0; i != N; ++ i) u += v;
return u;
}
[color=blue]
> BTW - there's no flame intended here at all.[/color]

None taken; likewise.

Buster.


  #27  
Old July 19th, 2005, 06:29 PM
Artie Gold
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Buster wrote:[color=blue]
> "Artie Gold" <artiegold@austin.rr.com> wrote
>[color=green]
>>Unless I'm missing something (not terribly unlikely), all the
>>examples provided only work when the actual array is in scope
>>at the point where its size is being asked (which means that
>>the size would be known anyway).[/color]
>
>
> No, you're quite right. As others have said, it's not terribly useful.
> But I have found something like the following handy in the past, to
> save a little typing.
>
> template <typename U, typename V, std::size_t N>
> U (& u) [N] add (U (& u) [N], V (& v) [N])
> {
> for (std::size_t i = 0; i != N; ++ i) u += v;
> return u;
> }
>
>[color=green]
>>BTW - there's no flame intended here at all.[/color]
>
>
> None taken; likewise.
>[/color]

Oh. Well. OK then!

Cheers,
--ag


--
Artie Gold -- Austin, Texas

  #28  
Old July 19th, 2005, 06:29 PM
Steven C.
Guest
 
Posts: n/a

re: Help with sizeof and pointers


I'm curious what news reader program u use that is better with bottom
posting.


"Kevin Goodsell" <usenet1.spamfree.fusion@neverbox.com> wrote in message
news:%Kw8b.1595$BS5.649@newsread4.news.pas.earthli nk.net...
Steven C. wrote:
[color=blue]
> You have two choices[/color]

Please don't top-post. Re-read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.


  #29  
Old July 19th, 2005, 06:29 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Steven C. wrote:[color=blue]
> I'm curious what news reader program u use that is better with bottom
> posting.
>[/color]

Correct posting does not depend on the news client. Please read the
following:

http://www.cs.tut.fi/~jkorpela/usenet/brox.html
http://www.caliburn.nl/topposting.html
http://www.dickalba.demon.co.uk/usen.../faq_topp.html

Top-posting is wrong. It violates internet standards. It's illogical. It
encourages over-quoting. You've been asked not to do it. If you have a
problem with that, I suggest you find a group that doesn't care how you
post. Here, we insist on proper posting (for many reasons).

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #30  
Old July 19th, 2005, 06:29 PM
White Wolf
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Steven C. wrote:[color=blue]
> I'm curious what news reader program u use that is better with bottom
> posting.[/color]

Steven!

I see you are using OutOfLuck Express (like I do). Look at this:

http://home.in.tum.de/~jain/software/oe-quotefix/

There you find a free (and good) little proggy, which will help you to make
proper posting with no effort. It fixes the non-standard Microsoft way of
quoting.

--
WW aka Attila


  #31  
Old July 19th, 2005, 06:29 PM
Steven C.
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Chill out I just asked! I guess it's kind of a religious thing with you.


  #32  
Old July 19th, 2005, 06:29 PM
Kevin Goodsell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


Steven C. wrote:
[color=blue]
> Chill out I just asked! I guess it's kind of a religious thing with you.
>
>[/color]

Please quote some context when replying. Assuming your reply was meant
for me, here's my response.

I read usenet a lot. I actively participate in groups, and I frequently
search the archives for information. Correct posting makes everything go
much more smoothly. It avoids confusion and misunderstandings, and keeps
the discussion organized and easy to follow. It also prevents wasted
time and space caused by overquoted replies. Isn't that worth a little
tiny bit of extra effort, especially considering 1) the size of the
audience (potentially thousands) and 2) the lifetime of the articles
(maybe forever)?

It's not as if these are arbitrary rules. They have a purpose, and were
determined to be the best practices based on experience.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

  #33  
Old July 19th, 2005, 06:30 PM
Jon Bell
Guest
 
Posts: n/a

re: Help with sizeof and pointers


In article <NfO8b.67839$IJ6.2019217@twister.socal.rr.com>,
Steven C. <nospam@xxx.com> wrote:[color=blue]
>I'm curious what news reader program u use that is better with bottom
>posting.[/color]

Actually, even with Outlook Express it's easy to post "properly". All you
have to do is start at the top where OE puts you to begin with, and scroll
down through the quoted text. As you go, delete the stuff that isn't
directly relevant to your response. When you come to a point that you
want to respond to, stop scrolling and put your comments after that point.
Then, if you're not at the end of the message yet, keep scrolling and
deleting, and inserting more comments if appropriate. Eventually you'll
reach the bottom, and your comments will be interspersed nicely among the
remaining quoted material, point/counterpoint style.

With this procedure, it's actually *better* to have the cursor at the top
to begin with. If the cursor starts out at the bottom, you have to scroll
all the way up to the top before you can start working your way down.

--
Jon Bell <jtbellap8@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
  #34  
Old July 19th, 2005, 06:30 PM
Jack Klein
Guest
 
Posts: n/a

re: Help with sizeof and pointers


On Sat, 13 Sep 2003 03:59:46 GMT, "Steven C." <nospam@xxx.com> wrote
in comp.lang.c++:
[color=blue]
> You have two choices either end your array with a unque int or pass the
> size.
>
> main()
> {
> int array[]={1,2,3,4,5,6,7,8};
> function (array, sizeof(array)/sizeof(int))
> }
>
> function(int *array, int size)[/color]
^^^

function(int *array, size_t size)[color=blue]
> {
> }
>
>
>
> "Metzen" <aniled@yahoo.com> wrote in message
> news:4e629682.0309121725.2407d28d@posting.google.c om...
> hello,
> ok, I want to find the length of an int array that is being passed to a
> function:
>
> main()
> {
> int array[]={1,2,3,4,5,6,7,8};
> function(array);
> }
> function(int *array)
> {
> int arraylen = sizeof(*array)/sizeof(int);
> }
>
>
> arraylen should be 8 I get 1.
>
> What am I doing Wrong?
>
> Thanx
>[/color]

Closed Thread