Bug 20669 – Deprecation when passing string length as printf argument
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-03-11T22:57:04Z
Last change time
2020-03-12T00:00:02Z
Assigned to
No Owner
Creator
moonlightsentinel
Comments
Comment #0 by moonlightsentinel — 2020-03-11T22:57:04Z
The lenght of a string can be passed as an additional argument preceding the pointer. But DMD issues a warning about missmatched argument types.
-------------------------------------
void main()
{
import core.stdc.stdio : printf;
string s = "Hello, World";
printf("%.s", s.length, &s[0]);
}
-------------------------------------
print.d(5): Deprecation: argument s.length for format specification "%.s" must be char*, not uint
Comment #1 by destructionator — 2020-03-11T23:43:45Z
does it help if you cast(int) that s.length?
Comment #2 by moonlightsentinel — 2020-03-11T23:50:22Z
No. I would assume that this modifier is not implemented (yet) based on the error message.
Comment #3 by moonlightsentinel — 2020-03-12T00:00:02Z
Actually, %.s denotes a string with width 0 (the number is optional), length as an additional argument requires an additional asterix %.*s.
Closing but we could probably improve the error message.