结构体数组值自动改变

兔子0204 2013-07-08 05:29:14
一个程序,首先给结构体成员node.name[]数组赋了值,之后在对其它结构体如load.name[]进行操作时,发现node.name[]数组的前8个名字被改变了,后面的没变。为何没有对node.name[]进行操作,它的值会自动改变?
...全文
276 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-07-10
  • 打赏
  • 举报
回复
Setting a Breakpoint When a Variable Changes Value To set a breakpoint when a variable changes value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the name of the variable. 4. Click OK to set the breakpoint. Setting a Breakpoint When an Expression Changes Value To set a breakpoint when an expression changes value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type an expression such as x+y. 4. Click OK to set the breakpoint. Setting a Breakpoint When an Expression Is True To set a breakpoint when an expression is true 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type an expression, such as x==3, that evaluates to true or false. 4. Click OK to set the breakpoint. Setting a Breakpoint on a Variable Outside the Current Scope To break on a variable outside the current scope 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the variable name. 4. Select the drop-down arrow to the right of the text box. 5. From the menu that appears, click Advanced. The Advanced Breakpoint dialog box appears. 6. In the Expression text box, type the function name and (if necessary) the filename of the variable. 7. Click OK to close the Advanced Breakpoint dialog box. The information that you specified appears in the Expression text box in the Breakpoints dialog box. 8. In the Breakpoints dialog box, click OK to set the breakpoint. Note You can enter context information directly into the Expression field, using the advanced breakpoints syntax. For details, see Using Advanced Breakpoint Syntax. Setting a Breakpoint When the Initial Element of an Array Changes Value To break when the initial element of an array changes value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the first element of the array (myArray[0], for example). 4. In the Number Of Elements text box on the Data tab, type 1. 5. Click OK to set the breakpoint on myArray [0]. Setting a Breakpoint When the Initial Element of an Array Has a Specific Value To break when the initial element of an array has a specific value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type an expression containing the initial element of the array (myArray[0]==1, for example). 4. In the Number Of Elements text box, type 1. 5. Click OK to set the breakpoint on myArray [0]. Setting a Breakpoint When a Particular Element of an Array Changes Value To break when a particular element of an array changes value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the element of the array (myArray[12], for example). 4. In the Number Of Elements text box, type 1. 5. Click OK to set the breakpoint on myArray [12]. Setting a Breakpoint When Any Element of an Array Changes Value To break when any element of an array changes value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the first element of the array (myArray[0]). 4. In the Number Of Elements text box, type the number of elements in the array. 5. Click OK to set the breakpoint on myArray. Setting a Breakpoint When Any of the First n Elements of an Array Change Value To break when any of the first n elements of an array change value 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the first element of the array (myArray[0], for example). 4. In the Number Of Elements text box, type n (for example, 10). 5. Click OK to set the breakpoint on myArray[0] through myArray[9]. Setting a Breakpoint When the Location Value of a Pointer Changes To break when the location value of a pointer changes 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the pointer variable name (p, for example). 4. Click OK to set the breakpoint. Setting a Breakpoint When the Value at a Location Pointed to Changes To break when the value at a location pointed to changes 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the dereferenced pointer variable name (*p or p->next, for example). 4. Click OK to set the breakpoint. Setting a Breakpoint When an Array Pointed to by a Pointer Changes To break when an array pointed to by a pointer changes 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the dereferenced pointer variable name (*p, for example). 4. In the Number Of Elements text box, type the length of the array in elements. For example, if the pointer is a pointer to double, and the array pointed to contains 100 values of type double, type 100. 5. Click OK to set the breakpoint. Setting a Breakpoint When the Value at a Specified Memory Address Changes To break when the value at a specified memory address changes 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type the memory address for the byte. For a word or doubleword memory address, enclose the address in parentheses, and precede it with a cast operator. For example, WO(21406036) for the word at memory location 21406036. Use the cast operator BY for a byte (optional), WO for a word, or DW for a doubleword. (The debugger interprets all integer constants as decimal unless they begin with zero (0) for octal or zero and x (0x) for hexadecimal.) 4. In the Number Of Elements text box, type the number of bytes, words, or doublewords to monitor. If you used the BY operator in the Expression field, specify the number of bytes. If you used WO, specify the number of words. If you used DW, specify the number of doublewords. 5. Click OK to set the breakpoint. Setting a Breakpoint When a Register Changes To break when a register changes 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type a register mnemonic, such as CS. 4. In the Number Of Elements text box, type the number of bytes to monitor. 5. Click OK to set the breakpoint. Setting a Breakpoint When a Register Expression Is True To break when a register expression is true 1. From the Edit menu, click Breakpoints. 2. Click the Data tab of the Breakpoints dialog box. 3. In the Expression text box, type an expression that contains a boolean comparison operator, such as CS==0. 4. In the Number Of Elements text box, type the number of bytes to monitor. 5. Click OK to set the breakpoint. Note When you set a data breakpoint, the debugger places the variable or variables used into a special debug register, if possible. The number of debug registers is limited. (Intel 80386 and later CPUs provide four debug registers. Motorola 680X0 and PowerPC chips have no debug registers.) Furthermore, stacked-based variables (parameters) cannot be placed into debug registers. If a breakpoint variable cannot be placed into a debug register, the debugger must examine the variable’s memory location after every instruction to determine whether the contents have changed. These extra memory accesses reduce execution speed of the program with the debugger. In some cases, the program may appear to hang. Performance may be especially slow if you are debugging a remote application.
www_adintr_com 2013-07-09
  • 打赏
  • 举报
回复
引用 5 楼 u011343898 的回复:
[quote=引用 4 楼 adlay 的回复:] [quote=引用 3 楼 u011343898 的回复:] [quote=引用 1 楼 adlay 的回复:] name 是怎么定义的? 多半是某个地方访问越界了. 在被改变的内存地址上下访问断点, 看是哪里在修改它吧.
struct NODE { char name[9]; }; 单步调试的时候发现在处理其它数据时,node.name[0]~node.name[7]变了.为何没有对node进行任何操作,却会对它产生影响呢?[/quote] 如果它们的内存指向了相同的位置就会 [/quote] 确实是它们的内存地址有重叠的地方。麻烦再问一下这种情况应该如何解决呢?[/quote] 让它们不重叠撒,又没有代码,只能你自己找重叠的原因了
兔子0204 2013-07-09
  • 打赏
  • 举报
回复
引用 4 楼 adlay 的回复:
[quote=引用 3 楼 u011343898 的回复:] [quote=引用 1 楼 adlay 的回复:] name 是怎么定义的? 多半是某个地方访问越界了. 在被改变的内存地址上下访问断点, 看是哪里在修改它吧.
struct NODE { char name[9]; }; 单步调试的时候发现在处理其它数据时,node.name[0]~node.name[7]变了.为何没有对node进行任何操作,却会对它产生影响呢?[/quote] 如果它们的内存指向了相同的位置就会 [/quote] 确实是它们的内存地址有重叠的地方。麻烦再问一下这种情况应该如何解决呢?
www_adintr_com 2013-07-08
  • 打赏
  • 举报
回复
引用 3 楼 u011343898 的回复:
[quote=引用 1 楼 adlay 的回复:] name 是怎么定义的? 多半是某个地方访问越界了. 在被改变的内存地址上下访问断点, 看是哪里在修改它吧.
struct NODE { char name[9]; }; 单步调试的时候发现在处理其它数据时,node.name[0]~node.name[7]变了.为何没有对node进行任何操作,却会对它产生影响呢?[/quote] 如果它们的内存指向了相同的位置就会
兔子0204 2013-07-08
  • 打赏
  • 举报
回复
引用 1 楼 adlay 的回复:
name 是怎么定义的? 多半是某个地方访问越界了. 在被改变的内存地址上下访问断点, 看是哪里在修改它吧.
struct NODE { char name[9]; }; 单步调试的时候发现在处理其它数据时,node.name[0]~node.name[7]变了.为何没有对node进行任何操作,却会对它产生影响呢?
qzf362269994 2013-07-08
  • 打赏
  • 举报
回复
具体代码贴出来看看
www_adintr_com 2013-07-08
  • 打赏
  • 举报
回复
name 是怎么定义的? 多半是某个地方访问越界了. 在被改变的内存地址上下访问断点, 看是哪里在修改它吧.

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧