Skip to main content
Lead II
May 6, 2024
Question

__DATE__ macro expansion incorrect in editor

  • May 6, 2024
  • 7 replies
  • 2966 views

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

 

7 replies

mƎALLEm
Technical Moderator
May 7, 2024

Hello,

I didn't reproduce the issue with CubeIDE 1.15.1 (today May 7th 2024):

SofLit_0-1715100169632.png

If you could share your sample project so I can reproduce it from my side. Also indicate the CubeIDE version you're using.

 

"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."
Lead II
May 7, 2024

I use STM32CubeIDE 1.11.2 at the moment. My system language is Dutch. I can check if the same problem persists with a newer version.
You did manage to reproduce part of the issue. The day of the month should not be left-padded with a zero, but with a space. If you compile GCC uses the proper format. It's only the preview in the editor that is incorrect.

"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."
mƎALLEm
Technical Moderator
May 8, 2024

Hello,

This is what I get with CubeIDE 1.15.1:

SofLit_1-1715159673670.png

Day of month is left padded with a space.

Ok then it's only the display popup is different but the string contains the correct char: a space. Do you see an issue in that behavior?

 

 

"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."
Lead II
May 8, 2024

Issues are only in macro expansion in editor (popup as you call it), not in binary.

I tested with a freshly generated project and an old project and in version 1.15.1 as well. Issue is not project specific.
In STM32CubeIDE 1.15.1 I get the same result as you. So only the left-padding issue, not the language or capitalization. And in 1.11.2 and 1.10.1 I see all three issues. So it seems the issue got half-fixed at some point.

"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."
mƎALLEm
Technical Moderator
May 8, 2024

Ok.

I'm not seeing a blocking issue in that since it's only a display and doesn't impact the cross-compilation result meanwhile I'm raising the internal ticket 180951 to fix this minor issue. This ticket is not accessible by community members.

I will get back to you for any feedback: to fix or not to fix.

"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."
Lead II
January 22, 2025

Problem with zero-padding still present in STM32CubeIDE V1.17.0.
Tested in windows sandbox to allow changing of system date (my work PC doesn't allow me to change system date).

"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."
mƎALLEm
Technical Moderator
January 22, 2025

Hello @unsigned_char_array 

I will keep you updated when it is 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."
Tesla DeLorean
Guru
January 22, 2025

Strikes me as a intrinsic MACRO furnished by STM32CudeIDE based on the date stamp of the file, rather than something GCC or VS is responsible for at this point.

The criticality of this is probably deemed quite low as it's more of a syntax-check / visual cue rather than something that materially impacts the code build. You have some compile time dependency on this?

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Andrew Neil
Super User
January 22, 2025

The __DATE__ macro is specified by the C language standard:

https://en.cppreference.com/w/cpp/preprocessor/replace#:~:text=expands%20to%20the%20date,is%20less%20than%2010

CubeIDE is not abiding by that standard.

 

A very minor point, IMO - but it is wrong.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Lead II
January 22, 2025

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."
Andrew Neil
Super User
January 22, 2025

@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 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
January 23, 2025

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

AndrewNeil_0-1737627408261.png

@mƎALLEm  - Maybe that would be a better solution?

 

PS:

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

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
Technical Moderator
January 23, 2025

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."
Andrew Neil
Super User
January 23, 2025

@mƎALLEm 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.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
mƎALLEm
Technical Moderator
January 23, 2025

@Andrew Neil wrote:

@mƎALLEm 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."
Lead II
January 23, 2025

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