NEWTON

NEWTON


Popular tags

    how I could read a felt* from ap in Cairo lang?

    Asked

    4 months ago

    63

    views


    0

    Hey folks, do you know how I could read a felt* from ap?

    I want to do something like this:

    let (hello : felt*) = alloc(); tempvar world : felt* = hello; let world_like : felt* = [ap-1];

    when I do tempvar world = hello, I ensure I add hello (the pointer) to [ap] and then I increase ap so world_like = [ap-1] should be the same thing than world

    But I get this error:

    Cannot assign an expression of type 'felt' to a reference of type 'felt*'.
        let world_like : felt* = [ap-1];
    

    When doing a similar code:

    let (func_pc: felt*) = get_label_location(storage_var); _prepare_call(pedersen_ptr, range_check_ptr, len_inputs, inputs + len_inputs); call abs ap[11 - 6 * 2];

    I get ``` Cannot apply subscript-operator to non-pointer, non-tuple type 'felt'. call abs ap[11 - 6 * 2]; // removing alloc_locals by calling ap[11-6*2] ?

    
    _This question was originally posted on [StarkNet Discord](https://www.newton.so/view?tags=discord)_
    
      cairo-beginnersdiscordcairo

    Newton

    asked

    4 months ago


    1 answers

    0

    Accepted answer

    have you tried let world_like : felt* = cast([ap-1], felt*);?

    This answer was originally posted on StarkNet Discord

    Newton

    answered

    4 months ago

    Your answer

    NEWTON

    NEWTON