file - Native C methods in Sedona - Level of Indirection -


i'm working in language called sedona can take native c methods. in order integrate c in sedona, variable declarations bit off.

  1. sedona -> c
    • bool -> int32_t
    • bool[] -> uint8_t*
    • byte -> int32_t
    • byte[] -> uint8_t*
    • short -> int32_t
    • short[] -> uint16_t*
    • int -> int32_t
    • int[] -> int32_t*
    • long -> int64_t
    • long[] -> int64_t*
    • float -> float
    • float[] -> float*
    • double -> double
    • double[] -> double*
    • obj -> void*
    • obj[] -> void**
    • str -> uint8_t*
    • str[] -> uint8_t**

my method trying open file, read contents , return contents of file string other sedona method use. know of don't know sedona, getting errors don't understand. here code:

#include <stdio.h> #include "sedona.h"  cell myweblet_mainweblet_getfile(sedonavm* vm, cell* params){     uint8_t* file_name = params[1].aval;     file *fp;     uint8_t* filecontents;     struct stat st;     stat(&file_name, &st);     int32_t size = st.st_size;     int32_t itter = 0;     cell result;      filecontents = malloc(sizeof(char)*size);     fp = fopen(file_name, "r"); //read mode      if (fp==null){         perror("error while opening file.\n");         exit(exit_failure);     }      unit8_t* ch;     while ((ch = fgetc(fp))!=eof){         filecontents[itter] = ch;         itter++;      }     result.aval = filecontents;     fclose(fp);     return result; } 

i'm getting more errors this, here example of pops up:

- warning c4047:'function' : 'const char *' differs in levels of indirection 'uint8_t **' - warning c4024:'stat' : different types formal , actual parameter 1 - error c2275: 'int32_t' : illegal use of type expression 

i want understand errors mean, don't need fix code me (although suggestions nice).

difference in level of indirection occurs when assign pointer variable non-pointer type, or more speaking when number of indirections (stars) in pointer variables differ. example, error in following (de)referencing cases.

int *x, y; x = y;  // correct use: x = &y; y = x;  // correct use: y = *x; 

in particular, error getting shows mismatch between formal , actual parameters. happens during function call when argument values pass on caller callee involves difference in indirection level. example follows.

void swap(int* x, int *y) { ... } int x = 2; y = 3; swap(x, y);  // correct use: swap(&x, &y); 

unfortunately, c not typed language , hence throws off warnings these types of errors. c++ however, reports these errors.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -