cancel
Showing results for 
Search instead for 
Did you mean: 

__DATE__ macro expansion incorrect in editor

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.

  • Month name is in Dutch
  • Month name is in lower case
  • Day of month is left-padded with 0 instead of a space

Schermafbeelding 2024-05-06 135149.png

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.
17 REPLIES 17

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.

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.

@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 

In the case of __GNUC__, the IDE doesn't even try to expand it:

AndrewNeil_0-1737627408261.png

@SofLit  - Maybe that would be a better solution?

 

PS:

But why does it say, "Write occurrence"? See separate thread.

SofLit
ST Employee

According to the internal feedback it isn't a GCC issue but rather a Eclipse CDT indexer issue.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: This is NOT an online support (https://ols.st.com) but a collaborative space. So please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

@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.


@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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
PS: This is NOT an online support (https://ols.st.com) but a collaborative space. So please be polite in your reply. Otherwise, it will be reported as inappropriate and you will be permanently blacklisted from my help/support.

I'm still suggesting that the best fix would be to not try to expand it at all - as for __GNUC__, et al.

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.

 

Kudo posts if you have the same problem and kudo replies if the solution works.
Click "Accept as Solution" if a reply solved your problem. If no solution was posted please answer with your own.