2024-05-06 06:48 AM - last edited on 2025-01-22 08:27 AM by Tesla DeLorean
Gcc and Visual Studio correctly compile today's date __DATE__ to "May 6 2024". However STM32CubeIDE editor expands the macro incorrectly if I hover the cursor over it.
2025-01-22 09:13 AM
It is indeed a relatively minor issue, but it can be frustrating if the editor lies to you about the value of a macro while debugging said macro. It also makes me distrust other values.
2025-01-22 10:10 AM - edited 2025-01-23 02:10 AM
@unsigned_char_array wrote:It also makes me distrust other values.
Probably unnecessarily:
This one is a Special Case: it is generated entirely internally by the compiler - so, unlike other macros, there's nowhere for the editor to get it from the Project or the Source files.
PS:
Here's the list of such Predefined Macros - for GCC:
https://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html
__DATE__, __TIME__, __FILE__, etc are among the Standard ones - defined by the language spec:
https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
2025-01-23 02:18 AM - edited 2025-01-23 03:56 AM
In the case of __GNUC__, the IDE doesn't even try to expand it:
@SofLit - Maybe that would be a better solution?
PS:
But why does it say, "Write occurrence"? See separate thread.
2025-01-23 04:33 AM
According to the internal feedback it isn't a GCC issue but rather a Eclipse CDT indexer issue.
2025-01-23 04:47 AM
@SofLit wrote:a Eclipse CDT indexer issue.
It can't be the indexer: as noted earlier, there is nothing to index - it is not defined anywhere in the source code nor in the Project settings.
So Eclipse must be making it up somewhere...
As also noted earlier, I think a better solution would be to treat it as for things like __GNUC__ - where it doesn't even try to expand it.
2025-01-23 04:54 AM - edited 2025-01-23 04:55 AM
@Andrew Neil wrote:
@SofLit wrote:
a Eclipse CDT indexer issue.
It can't be the indexer: as noted earlier, there is nothing to index - it is not defined anywhere in the source code nor in the Project settings.
So Eclipse must be making it up somewhere...
This is our expert analysis not mine ;) .. Anyway I will keep you informed when it will be fixed.
2025-01-23 05:04 AM
I'm still suggesting that the best fix would be to not try to expand it at all - as for __GNUC__, et al.
2025-01-23 06:28 AM
I tried to research the cause of the bug.
First I checked the Eclipse CDT repo: https://github.com/eclipse-cdt/cdt
I searched for the macro: https://github.com/search?q=repo%3Aeclipse-cdt%2Fcdt%20__DATE__&type=code
I found this function:
private static final DynamicMacro __DATE__ = new DateMacro("__DATE__".toCharArray()); //$NON-NLS-1$
And it uses DateMacro which has the following method:
private char[] createDate() {
char[] charArray;
StringBuilder buffer = new StringBuilder("\""); //$NON-NLS-1$
Calendar cal = Calendar.getInstance();
DateFormatSymbols dfs = new DateFormatSymbols(Locale.ENGLISH);
buffer.append(dfs.getShortMonths()[cal.get(Calendar.MONTH)]);
buffer.append(" "); //$NON-NLS-1$
int dom = cal.get(Calendar.DAY_OF_MONTH);
if (dom < 10) {
buffer.append(" "); //$NON-NLS-1$
}
buffer.append(dom);
buffer.append(" "); //$NON-NLS-1$
buffer.append(cal.get(Calendar.YEAR));
buffer.append("\""); //$NON-NLS-1$
charArray = buffer.toString().toCharArray();
return charArray;
}
These lines matter:
int dom = cal.get(Calendar.DAY_OF_MONTH);
if (dom < 10) {
buffer.append(" "); //$NON-NLS-1$
}
buffer.append(dom);
As you can see a space is inserted and not a 0. So this is not a bug in CDT. At least not in the current version.
In an earlier version there was the language of the month bug that was fixed Aug 30, 2024 by ST:
https://github.com/eclipse-cdt/cdt/commit/9b09dce3a05daef6aa2763de629e6f72650794ef
There was an issue about the day of month too: https://github.com/eclipse-cdt/cdt/pull/896
I think the issue is that the fix is after the latest CDT release: CDT 11.6.1 Jul 3, 2024. And STM32CubeIDE V1.17.0 uses 11.4.0.2023. So either we wait for CDT to create a new release and ST updating their version of CDT to that version or ST makes a hot fix.