Results 1 to 4 of 4

Thread: Warning when returning local address in non kernel function...

Hybrid View

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    12

    Warning when returning local address in non kernel function...

    Hi all,

    Here is a sample ..

    double* foo () {

    double result_reg[2];
    result_reg[0] = ...
    result_reg[1] = ...
    return result_reg;
    }

    I am not sure the content of result will not be erased, when exiting from foo(). Am I right, or is there a function address space like stack in C?
    Many thanks!
    Last edited by mbenguig; 05-31-2013 at 03:19 AM.

  2. #2
    This is problematic in OpenCL C as well regular C. The data contained in result_reg[] should be considered invalid when the function returns. So there's no legitimate purpose for returning a pointer to it from a function.

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    25
    Just pass the pointer in as an arg

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    12
    Ok, many thanks to all!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •