www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7872] New: dmd should warn if `printf` is used on D strings

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872

           Summary: dmd should warn if `printf` is used on D strings
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: jonas lophus.org


--- Comment #0 from Jonas H. <jonas lophus.org> 2012-04-09 08:19:32 PDT ---
string foo = "john";
printf("hello %s\n", foo);

doesn't work because `printf` expects a zero-terminated string.

The compiler should really yield a warning here.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #1 from bearophile_hugs eml.cc 2012-04-09 09:36:00 PDT ---
(In reply to comment #0)
 string foo = "john";
 printf("hello %s\n", foo);
 
 doesn't work because `printf` expects a zero-terminated string.
 
 The compiler should really yield a warning here.
In D string literals are zero-terminated. So this run correctly: import core.stdc.stdio; void main() { string foo = "john"; printf("hello %s\n", foo.ptr); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872



--- Comment #2 from Jonas H. <jonas lophus.org> 2012-04-09 11:26:57 PDT ---
Yeah but I guess it's a common mistake for someone coming from C/C++ so there
should be some guidance anyway.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #3 from Maxim Fomin <maxim maxim-fomin.ru> 2012-04-09 11:35:19 PDT
---
(In reply to comment #1)
 In D string literals are zero-terminated. So this run correctly:
 
If documentation (http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&;id=DanielKeep/TextInD&amp;oldid=StringsInD) is not mistaken string literals are zero-terminated in DMD, thus it is compiler-specific feature. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872



--- Comment #4 from Jonas H. <jonas lophus.org> 2012-04-09 11:40:53 PDT ---
For the record, some discussion on this is happening in the forum too.
http://forum.dlang.org/thread/ytoebhnapmcixfdtaoqd forum.dlang.org

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com


--- Comment #5 from Stewart Gordon <smjg iname.com> 2012-04-11 16:10:42 PDT ---
DMD should warn if printf is used full stop. :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 11 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7872



--- Comment #6 from Maxim Fomin <maxim maxim-fomin.ru> 2012-04-14 22:18:48 PDT
---
(In reply to comment #3)
 (In reply to comment #1)
 In D string literals are zero-terminated. So this run correctly:
 
If documentation (http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&;id=DanielKeep/TextInD&amp;oldid=StringsInD) is not mistaken string literals are zero-terminated in DMD, thus it is compiler-specific feature.
I just found that here (http://dlang.org/interfaceToC.html) is written that they actually are zero-terminated in D. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 14 2012