memccpy比SRC起始地址返回更低的内存地址 [英] memccpy return lower memory address than the src starting address

查看:256
本文介绍了memccpy比SRC起始地址返回更低的内存地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一所学校项目中,我不得不重新code中的 memccpy()功能。

I've got a school project where I have to recode the memccpy() function.

我用2程序来检查我的code正常工作。首先是一个小的程序,只有一个主。
第二个节目是由另一名学生developped(可这里发现,如果你想看到它)

I use 2 programs to check if my code works properly. The first is a small program with only a main. The second program is developped by another student (can be found here, if you want to see it)

使用我的程序,没有问题,我的两个m​​emccpy和原来的函数返回从DEST指针向右字符正确的指针。
但与第二程序,原函数返回低级指针ADRESS比目标寄存器指针起始ADRESS,例如:

With my program, there is no problem, both my memccpy and the original function return the right pointer on the right character from the dest pointer. But with the second program, the original function return a lower pointer adress than the dest pointer starting adress, for example:


  • 启动的src 价值地址: 0x7fff712edc40

  • Memccpy返回指针地址: 0x712edc44

  • 我memccpy函数返回指针: 0x7fff712edc44

  • Starting address of the src value: 0x7fff712edc40
  • Memccpy return pointer address: 0x712edc44
  • My memccpy function return pointer: 0x7fff712edc44

所以,有人编他的电脑和我的code返回正确的ADRESS,它必须来自第二个程序。

So, as someone compile on his computer and my code return the right adress, it must come from the second program.

是否有人知道是什么导致这种行为?

Does somebody know what can cause this kind of behavior?


  • 我试着在谷歌搜索得到的答复是不是非常有帮助。

  • 我读了男子多次^^(而不是更多的帮助)。

  • 我读到memccpy有当一个未定义的行为内存重叠,但他们不重叠。

下面是我的ft_memccpy()函数:

Here is my ft_memccpy() function:

void    *ft_memccpy(void *str_dest, const void *str_src, int c, size_t n)
{
    unsigned int    i;
    char            *dest;
    char            *src;
    char            *ptr;

    dest = (char *)str_dest;
    src = (char *)str_src;
    i = 0;
    ptr = 0;
    while (i < n && ptr == 0)
    {
        dest[i] = src[i];
        if (src[i] == ((char)c))
            ptr = dest + i + 1;
        i++;
    }
    return (ptr);
}

编辑:我编辑,因为我得到了downvote,许多用户不明白我的问题。所以,我认为这是不够清晰,我希望这将编辑^^。

I edited because i got downvote and many user didn't understood my question. So i thought that it was not clear enough, i hope this edit will ^^'.

推荐答案

这可能是64位指针和32位指针的问题。

That's probably the problem of the 64bit pointer and 32bit pointer.

ft_memccpy 将返回一个64位指针,因此它输出

Your ft_memccpy would return a 64 bit pointer, so it outputs

0x7fff712edc44

虽然系统 memccpy 返回一个32位的

0x712edc44

这篇关于memccpy比SRC起始地址返回更低的内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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