Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > passing array of floats (or vectors) into another function - datascope - hmmm. Very ugly...

Reply
Thread Tools

passing array of floats (or vectors) into another function - datascope - hmmm. Very ugly...

 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-20-2011
On 10/19/2011 6:16 PM, someone wrote:
> On 10/19/2011 10:34 PM, Jorgen Grahn wrote:
>> On Wed, 2011-10-19, someone wrote:
>>> On Oct 19, 4:08 pm, Jorgen Grahn<(E-Mail Removed)> wrote:
>>>> On Mon, 2011-10-17, Victor Bazarov wrote:
>>> There is no alternative to using global vars in that case, at least
>>> not AFAIK - is this right or not?

>>
>> Perhaps I used the word "global" a bit sloppily; it could e.g. be
>> something like:
>>
>> int * get_the_data()
>> {
>> static int foo;
>> return&foo;
>> }
>>
>> but that doesn't really help much.

>
> Because that is not thread-safe ? Not sure I understand why "global" was
> used sloppily, neither not sure of the purpose of this get_the_data()
> function. Isn't this get_the_data() function a global function, so
> instead foo could just as well be a global variable - the result is the
> same: Ugly?
>
> Foo is static, so it exists until the program terminates... Static is
> not thread-safe, right? I think I can see that this doesn't really help
> much, I'm just only 95% sure of the explanation...


Well, at least it does give you the ability to track (by adding some
kind of logging code) when access to the data is made. Beyond that,
there is no difference, I believe.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      10-20-2011
On Wed, 2011-10-19, someone wrote:
> On 10/19/2011 10:34 PM, Jorgen Grahn wrote:
>> On Wed, 2011-10-19, someone wrote:
>>> On Oct 19, 4:08 pm, Jorgen Grahn<(E-Mail Removed)> wrote:
>>>> On Mon, 2011-10-17, Victor Bazarov wrote:
>>> There is no alternative to using global vars in that case, at least
>>> not AFAIK - is this right or not?

>>
>> Perhaps I used the word "global" a bit sloppily; it could e.g. be
>> something like:
>>
>> int * get_the_data()
>> {
>> static int foo;
>> return&foo;
>> }
>>
>> but that doesn't really help much.

>
> Because that is not thread-safe ? Not sure I understand why "global" was
> used sloppily,


Because when I myself hear "global" I think "global" as in

int foo;

at the top-level, not static as in

static int foo;

or static inside a function or class.

> neither not sure of the purpose of this get_the_data()
> function.


There is no purpose, other than to illustrate my point.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
 
someone
Guest
Posts: n/a
 
      10-20-2011
On 2011-10-20 15:50, Jorgen Grahn wrote:
> On Wed, 2011-10-19, someone wrote:
>> On 10/19/2011 10:34 PM, Jorgen Grahn wrote:
>>> On Wed, 2011-10-19, someone wrote:
>>>> On Oct 19, 4:08 pm, Jorgen Grahn<(E-Mail Removed)> wrote:
>>>>> On Mon, 2011-10-17, Victor Bazarov wrote:
>>>> There is no alternative to using global vars in that case, at least
>>>> not AFAIK - is this right or not?
>>>
>>> Perhaps I used the word "global" a bit sloppily; it could e.g. be
>>> something like:
>>>
>>> int * get_the_data()
>>> {
>>> static int foo;
>>> return&foo;
>>> }
>>>
>>> but that doesn't really help much.

>>
>> Because that is not thread-safe ? Not sure I understand why "global" was
>> used sloppily,

>
> Because when I myself hear "global" I think "global" as in
>
> int foo;
>
> at the top-level, not static as in
>
> static int foo;
>
> or static inside a function or class.


Ah, I see... I think I understand you.

>> neither not sure of the purpose of this get_the_data()
>> function.

>
> There is no purpose, other than to illustrate my point.


Ok, thanks.
 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      10-20-2011
On 2011-10-20 14:13, Victor Bazarov wrote:
> On 10/19/2011 6:16 PM, someone wrote:
>> On 10/19/2011 10:34 PM, Jorgen Grahn wrote:
>>> On Wed, 2011-10-19, someone wrote:
>>>> On Oct 19, 4:08 pm, Jorgen Grahn<(E-Mail Removed)> wrote:
>>>>> On Mon, 2011-10-17, Victor Bazarov wrote:
>>>> There is no alternative to using global vars in that case, at least
>>>> not AFAIK - is this right or not?
>>>
>>> Perhaps I used the word "global" a bit sloppily; it could e.g. be
>>> something like:
>>>
>>> int * get_the_data()
>>> {
>>> static int foo;
>>> return&foo;
>>> }
>>>
>>> but that doesn't really help much.

>>
>> Because that is not thread-safe ? Not sure I understand why "global" was
>> used sloppily, neither not sure of the purpose of this get_the_data()
>> function. Isn't this get_the_data() function a global function, so
>> instead foo could just as well be a global variable - the result is the
>> same: Ugly?
>>
>> Foo is static, so it exists until the program terminates... Static is
>> not thread-safe, right? I think I can see that this doesn't really help
>> much, I'm just only 95% sure of the explanation...

>
> Well, at least it does give you the ability to track (by adding some
> kind of logging code) when access to the data is made. Beyond that,
> there is no difference, I believe.


Yep, agreed, thanks.
 
Reply With Quote
 
someone
Guest
Posts: n/a
 
      10-20-2011
On 2011-10-20 09:18, Werner wrote:
> On Oct 19, 6:36 pm, someone<(E-Mail Removed)> wrote:
>>
>> By the way: How come you code on that webpage? Or I assume you made the
>> program on your own pc and then copy/pasted it?

>
> perhaps OT... but
>
> - I don't need to create a project everytime.
> - I can use the latest compiler...
> - It's a nice way of sharing ideas. It's certainly a
> better way of looking at the code that using a
> newsreader. [You] can compile and run it
> immediately
> - The only disadvantage I see is that I don't know
> how persistent the code is (how long it will remain
> there).
>
> Of course when I do work I code on my PC/Notebook etc.


Ok, I see... I still prefer my own pc which compiles without "lagging"

> Glad to be of help.


And a very good help, you were
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      10-24-2011
Manual morphing the type of a pointer which points to different types in the run time without a clear purpose is a useful trick, but this trick is not recommended in C++ most of the time.
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      10-24-2011
On Mon, 2011-10-24, 88888 Dihedral wrote:
> Manual morphing the type of a pointer which points to different
> types in the run time without a clear purpose is a useful trick, but
> this trick is not recommended in C++ most of the time.


I *think* I agree with what you *really* mean, but what you write
makes no sense. How can something "without a clear purpose" be a
"useful trick", and what do you really mean?

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do you convert and array of doubles into floats? SpreadTooThin Python 7 09-16-2006 01:14 AM
passing function into another function Joe Van Dyk Ruby 2 09-11-2006 11:21 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
Quick Book file access very very very slow Thomas Reed Computer Support 7 04-09-2004 08:09 PM
very Very VERY dumb Question About The new Set( ) 's Raymond Arthur St. Marie II of III Python 4 07-27-2003 12:09 AM



Advertisments