子程序使用错误的值 [英] Subroutine uses wrong value

查看:78
本文介绍了子程序使用错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从另一个接收文件名的子程序。这个子程序与其他三个调用程序一起工作,但今天我添加了另一个,并且由于某种原因它找到了一些其他文件名。嘿,我调用例程xml_load_file(DEALS),其中DEALS在别处被定义为../ options / deals.xml。参数定义为char *。如果我在xml_load_file()的开头打印出文件名,它会显示一个完全不同的路径和文件:../carts/12345这是一个合法的文件名,但我不知道它是如何得到的。


我为循环真正抛出的是我创建的test_load(char * p)除了打印出* p之外什么也没做什么,把它放在与xml_load_file()相同的文件中,并显示正确的文件名。


这对任何人来说都响了吗?在Linux上使用gcc。

I have a subroutine that receives a filename from another. This sub has worked with three other calling programs but, today, I added another and for some reason it finds some other file name to use. iow, I call the routine xml_load_file(DEALS) where DEALS is elsewhere defined as "../options/deals.xml". The argument is defined as a char*. If I print out the filename at the beginning of xml_load_file(), it shows an entirely different path and file: ../carts/12345 which is a legitimate filename but I don''t have a clue how it got that.

What really throws me for a loop is I create "test_load(char *p)" which does nothing but print out what *p is, put it in the same file as xml_load_file() and that shows the correct file name.

Does this ring a bell with anyone? Using gcc on Linux.

推荐答案

对我来说听起来很奇怪Doc。


我会使用gdb逐步完成程序如果代码检查不明显,请看看实际发生了什么。
Sounds very strange to me Doc.

I would step through the program using gdb and see what is actually happening if it is not obvious from code examination.


在行之间读取,我假设程序的相关部分看起来像这样:
Reading between the lines, I assume that the relevant portion of your program looks something like this:
展开 | 选择 | Wrap | 行号


几乎所显示的内容。从主要作品调用它。 test_load(),虽然我以不同方式显示,但没有。从这个特定子程序调用不会。我也把文件的strcpy作为[FILENAME]并用指针调用了sub但是它失败了。


如果我把一个打印声明放在xml_load_file()的第一行,它显示错误的文件名;它永远不会收到正确的。
Pretty much what you show. Calling it from main works. test_load(), though I show it differently, does not. Calling from this one particular subroutine does not. I also did a strcpy of the filename to a s[FILENAME] and called the sub with a pointer to that but it fails.

What mystifies me is if I put a print statement on the first line of xml_load_file(), it shows the wrong filename; it never receives the correct one.
展开 | 选择 | Wrap | 行号


这篇关于子程序使用错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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