<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call]]></title><description><![CDATA[<p dir="auto">Hi all</p>
<p dir="auto">Here is my C code, run on the Qt-Creator debugger:</p>
<pre><code>char** inArray(char* array1[], int sz1, char* array2[], int sz2, int* lg) {
    // some things
}

int main()
{
    char* arr1[3] = { "arp", "live", "strong" };
    char* arr2[5] = { "lively", "alive", "harp", "sharp", "armstrong" };

    int lg = 3;

    char** res = inArray(arr1, 3, arr2, 5, &amp;lg);
}
</code></pre>
<p dir="auto">On the line <code>char** res = inArray(arr1, 3, arr2, 5, &amp;lg);</code> the debugger reports:<br />
<img src="https://i.stack.imgur.com/sA6tK.png" alt="alt text" class=" img-fluid img-markdown" /></p>
<p dir="auto">But on the first line of inArray, it reports:<br />
<img src="https://i.stack.imgur.com/KlvqN.png" alt="alt text" class=" img-fluid img-markdown" /></p>
<p dir="auto">I suppose it's very basic, but I don't understand why the 2 values are not identical.</p>
<p dir="auto">KR<br />
Marc</p>
]]></description><link>https://forum.qt.io/topic/119901/debugger-reports-what-can-seem-to-be-inconsistent-values-just-before-and-at-the-beginning-of-a-function-call</link><generator>RSS for Node</generator><lastBuildDate>Thu, 07 May 2026 19:59:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/119901.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 13 Oct 2020 11:48:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Thu, 15 Oct 2020 10:02:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a><br />
I do see it as "wrong".  The debugger shows, in two different places, that <code>array1[2]</code> is a <code>char</code> (value <code>'p'</code>) and it is a <code>char *</code> (value <code>"strong"</code>).  That's just plain "wrong".  And btw I don't think this has anything to do with "QtC debugger", Qt Creator just gets its information from the debugger, so (I assume, though untested) this is 100% a <strong>gdb</strong> vs <strong>MSVC</strong> issue.</p>
]]></description><link>https://forum.qt.io/post/622365</link><guid isPermaLink="true">https://forum.qt.io/post/622365</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 15 Oct 2020 10:02:04 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Thu, 15 Oct 2020 12:16:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/622343">Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call</a>:</p>
<blockquote>
<p dir="auto">I see this as "wrong"</p>
</blockquote>
<p dir="auto">I wouldnt say it's wrong, it's just weird or somehow confusing since arrays are passed to function by passing the (pointer to / address of) first element. So, if the debugger only sees the first element, the data type <code>char *</code> would be correct in this case.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/622343">Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call</a>:</p>
<blockquote>
<p dir="auto">char **array1 and  char *array[3] instead of char *array[]</p>
</blockquote>
<p dir="auto">They are similar but not the same nor (directly) interchangeable. A <code>char **</code> can only be a pointer to one element and can not replace the whole array structure, since you need at least some length parameters or any size :)</p>
<p dir="auto">And I guess this is exactly what QtC does. The function gets an array of char pointers, which is a pointer to its first element itself. This is passed to the function and used as <code>char *[]</code>. It depends how QtC debugger (on linux gdb) interprets this parameter and perhaps any conversion to plain <code>char * []</code> happens,  when being inside <code>inArray</code> function?! And maybe Visual Studio and MSVC are "smarter" or interpret this structure differently...</p>
<p dir="auto">Interesting stuff to read :)<br />
<a href="http://www.lysator.liu.se/c/c-faq/c-2.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.lysator.liu.se/c/c-faq/c-2.html</a></p>
]]></description><link>https://forum.qt.io/post/622361</link><guid isPermaLink="true">https://forum.qt.io/post/622361</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 15 Oct 2020 12:16:51 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Thu, 15 Oct 2020 08:17:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zlotz">@<bdi>Zlotz</bdi></a><br />
You may be happy to have closed this, but I decided to do some investigations myself, as it's bothering me!</p>
<p dir="auto">I am Ubuntu, gcc 9.3.0, gdb 9.2.  I made a C-only project (also tried as CPP project, no difference).  I confirm that I see the same behaviour as you show in your screenshots, and note this is different from what <a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a> reported in MSVC.</p>
<p dir="auto">I also tried declaring the parameter as <code>char **array1</code> and  <code>char *array[3]</code> instead of <code>char *array[]</code>, and also put in <code>const</code>s, but it did not alter.</p>
<p dir="auto">Like you, in the autos window I see <code>array1</code> as type <code>char *</code>, with value <code>"arp"</code> and in the expansion, say, <code>[2]   'p'</code>.  In the debugger watch window, I enter expressions <code>array1</code>, <code>array1[0]</code> &amp; <code>array1[2]</code>.  With the following output:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/235b6d24-7b6f-4c3f-b989-1807fa00b9c7.png" alt="Screenshot from 2020-10-15 08-44-59.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">As you can see in the watch window, there are <em>two</em> different values for, say, <code>array1[0]</code> or <code>array1[2]</code>!  The first expression shows <code>array1[2]  'p'  char</code> while the last expression shows <code>array1[2]  "strong"  char *</code>, or <code>array1</code> being shown as type <code>char *</code> with value <code>"arp"</code> and <code>array1[0]</code> being shown as exactly the same!</p>
<p dir="auto">I see this as "wrong" in <strong>gdb</strong>, and you are entitled to complain about "inconsistent values" here!  There is perhaps an explanation of this behaviour out there under <strong>gdb</strong>, but I don't know what words to use to Google for it....</p>
<p dir="auto">At some level, the fact that <code>array1</code> and <code>array1[0]</code> have the same memory address may be related to the issue.</p>
<p dir="auto">Now, if one of our resident C++ experts would care to comment on this <strong>gdb</strong> behaviour, which seems brain-damaged to me, I should be most interested to read....</p>
]]></description><link>https://forum.qt.io/post/622343</link><guid isPermaLink="true">https://forum.qt.io/post/622343</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 15 Oct 2020 08:17:30 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Wed, 14 Oct 2020 12:14:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zlotz">@<bdi>Zlotz</bdi></a> said in <a href="/post/622181">Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call</a>:</p>
<blockquote>
<p dir="auto">It's OK for me. Must I do something to close the topic ?</p>
</blockquote>
<p dir="auto">"Topic Tools/Mark as solved"</p>
]]></description><link>https://forum.qt.io/post/622185</link><guid isPermaLink="true">https://forum.qt.io/post/622185</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 14 Oct 2020 12:14:56 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Wed, 14 Oct 2020 11:47:48 GMT]]></title><description><![CDATA[<p dir="auto">Well, I guess that the debugger shows only the first value of the array for the same reason we have to pass lengths of arrays as parameters in C.</p>
<p dir="auto">It's OK for me. Must I do something to close the topic ?</p>
]]></description><link>https://forum.qt.io/post/622181</link><guid isPermaLink="true">https://forum.qt.io/post/622181</guid><dc:creator><![CDATA[Zlotz]]></dc:creator><pubDate>Wed, 14 Oct 2020 11:47:48 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Wed, 14 Oct 2020 10:07:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a><br />
Your MSVC behaviour is what I would expect.  So I assume OP is instead <code>gdb</code>, and then I don't understand why it is showing as he says it is.</p>
]]></description><link>https://forum.qt.io/post/622163</link><guid isPermaLink="true">https://forum.qt.io/post/622163</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 14 Oct 2020 10:07:23 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Wed, 14 Oct 2020 09:44:05 GMT]]></title><description><![CDATA[<p dir="auto">My MSVS debugger displays <code>array1</code> and <code>array2</code>inside <code>inArray</code> function as <code>char**</code> and their first element ("arp" / "lively") as <code>char *</code></p>
<p dir="auto">That shows, that you pass a pointer to a char pointer array (type of <code>arr1</code>) to your function <code>inArray</code>, which is also stated here:<br />
<a href="https://stackoverflow.com/questions/32377418/how-many-ways-are-there-to-pass-char-array-to-function-in-c" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/32377418/how-many-ways-are-there-to-pass-char-array-to-function-in-c</a></p>
]]></description><link>https://forum.qt.io/post/622150</link><guid isPermaLink="true">https://forum.qt.io/post/622150</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Wed, 14 Oct 2020 09:44:05 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Wed, 14 Oct 2020 09:05:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zlotz">@<bdi>Zlotz</bdi></a> said in <a href="/post/622098">Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call</a>:</p>
<blockquote>
<p dir="auto">No. It's <code>char*</code>.</p>
</blockquote>
<p dir="auto">And that is your problem here.  And, yes, the debugger display stuff can be a bit different from what you might think from looking at your code.</p>
<p dir="auto">Having said that, I'm not sure why your <code>char* array1[]</code> parameter declaration is coming out as <code>char *</code>.  Your code is C not C++ if it makes any difference to the debugging engine.  I take you do <em>not</em> declare the <code>inArray()</code> function anywhere else, e.g. in a <code>.h</code> file?  Make absolutely sure you have recompiled.</p>
]]></description><link>https://forum.qt.io/post/622145</link><guid isPermaLink="true">https://forum.qt.io/post/622145</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 14 Oct 2020 09:05:45 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Tue, 13 Oct 2020 22:56:05 GMT]]></title><description><![CDATA[<p dir="auto">No. It's <code>char*</code>.</p>
<p dir="auto">But I may start understanding.</p>
<p dir="auto">Do you mean that the debugger, for any reason, interprets the data differently when in the called function, but at least tells how it interprets the data ?</p>
]]></description><link>https://forum.qt.io/post/622098</link><guid isPermaLink="true">https://forum.qt.io/post/622098</guid><dc:creator><![CDATA[Zlotz]]></dc:creator><pubDate>Tue, 13 Oct 2020 22:56:05 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Tue, 13 Oct 2020 18:03:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zlotz">@<bdi>Zlotz</bdi></a><br />
The clue/reason will lie in the <strong>Type</strong> column in the debugger.  In your first screenshot I can (just) see it's <code>char *[3]</code>.  Redo your second screenshot to show what <strong>Type</strong> the debugger using there?  <code>char **</code>?</p>
]]></description><link>https://forum.qt.io/post/622071</link><guid isPermaLink="true">https://forum.qt.io/post/622071</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 13 Oct 2020 18:03:26 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Tue, 13 Oct 2020 16:15:29 GMT]]></title><description><![CDATA[<p dir="auto">What do you mean by "my char**" ? array1 ? The return of inArray ?</p>
<p dir="auto">OK but, as arr1 has the same type in main than array1 in inArray, why what you write doesn't apply to the first case ?<br />
Does the char*[] of main kind of becomes a char** to the debugger's eye on the call ?</p>
<p dir="auto">It's an exercise, I didn't decide the type of the function.</p>
<p dir="auto">What do you mean by "actual array use" ?</p>
]]></description><link>https://forum.qt.io/post/622067</link><guid isPermaLink="true">https://forum.qt.io/post/622067</guid><dc:creator><![CDATA[Zlotz]]></dc:creator><pubDate>Tue, 13 Oct 2020 16:15:29 GMT</pubDate></item><item><title><![CDATA[Reply to Debugger reports what can seem to be inconsistent values just before and at the beginning of a function call on Tue, 13 Oct 2020 15:25:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zlotz">@<bdi>Zlotz</bdi></a></p>
<p dir="auto">The first case is an address (<code>0x....</code>) / pointer to your char array and in the second case it's one char array of your <code>char **</code>.</p>
<p dir="auto">Arrays in C/C++ are stored in memory by using the pointer to first element. This is why you get the first / starting element inside your function - because you've passed the address of your array = address of first element = " <code>arp</code>"</p>
<p dir="auto">Is there a reason why you use <code>char **</code> and no <code>std::string</code> or <code>QString</code> arrays?</p>
<p dir="auto">EDIT:<br />
To change or access the actual array use<br />
<code>*array[0]</code> for example.</p>
]]></description><link>https://forum.qt.io/post/622057</link><guid isPermaLink="true">https://forum.qt.io/post/622057</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Tue, 13 Oct 2020 15:25:15 GMT</pubDate></item></channel></rss>