Re: To find the size of array using its pointer
From: Lawrence Kirby (lknews_at_netactive.co.uk)
Date: 01/20/05
- Next message: m: "Re: array riddle in c"
- Previous message: Ben Pfaff: "Re: problem with round"
- In reply to: Sontu: "Re: To find the size of array using its pointer"
- Next in thread: Chris Croughton: "Re: To find the size of array using its pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 20 Jan 2005 18:09:42 +0000
On Thu, 20 Jan 2005 09:06:25 -0800, Sontu wrote:
> Thanks. So nice of you all, for replying, but I think if i tell you my
> intent then my problem will become much clearer.
>
> In C, parameters to functions are either passed using "call by value"
> or "call by reference" [infact only "call by value", "call by
> reference" can be considered as the former if value is address].
>
> Now if need to implement "call by value-result", precisely on EXISTING
> CODE, what should i do?
I think you'd really need to convince us that this is a sensible thing to
do. Presumably thr existing code is designed to work without these "call
by value-result" semantics so why change it? What are you REALLY trying to
achieve? What you are describing is a means, not an end.
> I mean,
>
> int main(void)
> {
> char buffer[20];
> func(buffer);
> }
> }
> }
> void func(char *bufpas)
> {
> char _buffer[20]; //temporary array
> memcpy(_buffer,bufpas,20);
How does the existing func() code know how big buffer is?
> ......
> ...
>
> memcpy(bufpas,_buffer,20);
> }
> }
> should happen. For this to happen either i can use source-2-source
> transformation
Then maybe you can add an extra size argument automatically. It may not be
easy to figure out the needed size though, e.h. if the caller is passing a
value from a pointer variable rather than a declared array directly.
> or modify the compiler.
I doubt whether that will be a viable alternative.
> But in any case i need to know
> the size of "bufpas" to allocate a temporary array of same size.
>
> If its not clear, kindly mention, i will try to make it comprehensive.
My reaction to how to do something like this is "don't", reexamine the
underlying problem and find a better solution. Which brings us back to my
original qustion, what are you really trying to do?
Lawrence
- Next message: m: "Re: array riddle in c"
- Previous message: Ben Pfaff: "Re: problem with round"
- In reply to: Sontu: "Re: To find the size of array using its pointer"
- Next in thread: Chris Croughton: "Re: To find the size of array using its pointer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|