#&rvalue passed for void **

43 messages · Page 1 of 1 (latest)

ancient compass
#

Context:

Status Allocate(void **inst, const size_t nmemb, const size_t size);

# define ref(inst, type, index)                            \
  ({                                                       \
    type *_ref = NULL;                                     \
    fail(call(Array, type, RefIdx)                         \
         with (inst, (index), &_ref));                     \
    _ref;                                                  \
  })

Usage:

fail(Allocate(&ref(inst, type, i), 1, sizeof(type)));

Problem:
Fetching for the address of rvalue.

Personal Consideration:
Rather not solving it by having another lvalue variable to store rvalue.

hoary folioBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

runic spruce
ancient compass
#

it's simply not possible to have a pointer pointing towards something beyond its existence

runic spruce
#

I would recommend making ref a function

#

instead of this macro

ancient compass
#

let me see...

runic spruce
#

seems strange to only do it for 2/3 parameters as well

ancient compass
#

alas, the type is all about making this flexible on types. it wouldn't do if ref is a function

runic spruce
ancient compass
ancient compass
#

still, I have to try it before tagging this thread solved

#

but thanks anyway :)

hoary folioBOT
#

@ancient compass Has your question been resolved? If so, type !solved :)

ancient compass
#

okay, I think I solved it by adding a &

#
# define ref(inst, type, index)                            \
  ({                                                       \
    type *_ref = NULL;                                     \
    fail(call(Array, type, RefIdx)                         \
         with (inst, (index), &_ref));                     \
    &_ref;                                                 \
  })
runic spruce
#

nice dangling pointer

ancient compass
#

oh I forgot that

#

snap

runic spruce
ancient compass
#

actually I was wondering why my valgrind complained and the program didn't output anything expected :'D

runic spruce
#

and just do something like #define ref(inst,type,index)((type*)ref_(inst,index))

ancient compass
runic spruce
#

where ref_ does everything without the type information

ancient compass
#

well, unfortunately, the type is needed for calling array operations

#

I tried

runic spruce
#

are fail, call, and with also macros

ancient compass
#

wait, let me see your reply again...

#

yes

#

but fail is not involved

#

in this case anyway

runic spruce
#

what's the reason to have all of these macros

ancient compass
ancient compass
#
/* Converts calling function with compatible Incompleted objects. */
# define call(incompleted, type, operation)                \
  type##incompleted##_##operation

so the array operations are actually intArray_GetIdx

#

and since there is no dry array without type, it is required to use type on distinguishing one from another, like intArray from doubleArray

ancient compass
#

I think I got to go the long way, using stack. anyway, it's basically solved by now, thanks again

#

!solve

hoary folioBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity