分配使得指针从int瓦特/出一个投 [英] Assignment makes pointer from int w/out a cast

查看:97
本文介绍了分配使得指针从int瓦特/出一个投的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译一些code为memoizes Fibonacci数的程序。该项目工程完美然而,当我在Linux环境下编译我在编译之前得到这样的警告。

I am compiling some code for a program that memoizes fibonacci numbers. The program works perfectly however when I compile in linux environment I get this warning before compiling.

line 61: warning: assignment makes pointer from integer without a cast [enabled by default]

下面是此警告的是来自的code的片段,我会尽力展现最相关的事情,才能psented形势最好的图片$ P $

Here is a snippet of code of where this warning is coming from, I'll try to show things of most relevance to get the best picture presented of the situation

int InitializeFunction(intStruct *p, int n)

    p->digits = (int)malloc(sizeof(int) * 1);

        if(p->digits == NULL)
            handleError("Got error");

    //making the one index in p->digits equal to n
    p->digits[0] = n;

    //incrementing a field of 'p'
    p->length++;

    //return 1 if successful
    return 1;

此功能仅一个非常特定的目的叫了两声。它是用来初始化两个基例Fibonacci序列F [0] = 0&安培; F [1] = 1,这是它的唯一目的。所以,如果我通过引用传递特定的索引的地址结构的数组,它只是应该初始化这些值:

This function is only called twice for a very specific purpose. it is used to initialize the two base cases in the fibonacci sequence f[0] = 0 & f[1] = 1. That's it's only purpose. So if I pass by reference the address of a specific index in an array of structs it's just supposed to initialize those values:

Initializer(&someIntStruct[0], 0) ---->  after function -> someIntStruct[0] == 0
Initializer(&someIntStruct[1], 1) ---->  after function -> someIntStruct[1] == 1

想法?

推荐答案

改变

p->digits = (int)malloc(sizeof(int) * 1);

p->digits = (int*)malloc(sizeof(int) * 1);

这篇关于分配使得指针从int瓦特/出一个投的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆