Two handles to same variable in C -
is there way can create 2 variables point same memory location, can read same memory int, float, char, way like?
i want this, without pointer f, not have dereference every time read/write f.
char myarray[100]; float* f = (float *)&myarray[10];   i want closest thing c++'s reference in c.
i hope question makes sense.
edit: read stream (4 kb worth) of bytes flash memory. stream contains shorts, ints , floats. know locations of these ints , floats in array. , want read/write aforementioned ints , floats ordinary variables.
this example reads data predefined struct, packed (if necessary). beware of endian-ness! , of data types: int on target might short on pc.
#include<stdio.h>  #pragma pack(push, 1) struct mydata {     int version;     char title[16];     float reading[8]; } mydata;  #pragma pack(pop)  int main(void) {     file *fp;     struct mydata data = {0};     fp = fopen("mydata.bin", "rb");      if (1 != fread(&data, sizeof(data), 1, fp))         { // error         }      printf("version = %d\n", data.version);      fclose(fp);     return 0; }      
Comments
Post a Comment