lotabout / write-a-C-interpreter

Write a simple interpreter of C. Inspired by c4 and largely based on it.

Repository from Github https://github.comlotabout/write-a-C-interpreterRepository from Github https://github.comlotabout/write-a-C-interpreter

memcmp函数的问题

sundyloveme opened this issue · comments

你好。看了你的《手把手教你做一个 C 语言编译器》。动手实践时遇到问题,苦恼很久。
if (current_id[Hash] == hash && !memcmp( (char *)current_id[Name], last_pos, src - last_pos) )
请问这句中的:memcmp( (char *)current_id[Name], last_pos, src - last_pos)是用来 截取一段字符串赋值给current_id[Name]的嘛?
因为int memcmp ( const void * ptr1, const void * ptr2, size_t num );这个是memcmp 的原型。感觉您的用法很特殊啊!最后一个参数不应该是数字嘛?

谢谢!

突然间想明白了。不用回答了。
谢谢

memcmp字面意思就是内存比较呀。要能直接做赋值岂不是天下大乱了。两个指针相减不就是数字么?