Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C: Casting an int array to a double array?

  • 09-12-2004 10:30PM
    #1
    Registered Users, Registered Users 2 Posts: 3,359 ✭✭✭


    Is it possible to convert an int array to a double array?

    I have written a function which accepts an array of doubles as an argument.

    Most of the time I will be passing an array of doubles to it, but in one location in my program, I need to pass an array of ints to it.

    I've tried casting the array to a double array, but no luck.

    Is there a way of doing this? I might be doing it wrong.

    I suppose I could always use a for loop to cast each individual array element to a double, and then put those doubles into a new array...


Comments

  • Registered Users, Registered Users 2 Posts: 1,865 ✭✭✭Syth


    A for loop does seem like the best way to do it...


  • Registered Users, Registered Users 2 Posts: 3,359 ✭✭✭radiospan


    Yep, that did it, thanks.
    for( i= 0; i<= 7; i++ ) {
    				doublebytes[i] = double(bytes[i]);
    			}
    


  • Registered Users, Registered Users 2 Posts: 7,289 ✭✭✭kenmc


    why would you not handle it as a double always?
    or, at least pass it as an unadulterated array to the function and let the function cast the necessary elements to ints inside it if it still needs to play with ints??
    but yeah, you basically can't cast an array of things at once


Advertisement