473,388 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Get the 'L' out of here!

The following line of code:

m_Font = gcnew System::Drawing::Font( L"Arial", 10 ) ;

also works like this:

m_Font = gcnew System::Drawing::Font( "Arial", 10 ) ;

Note that the 'L' in front of "Arial" is missing in the second version. What
is the difference, if any, between L"string" and "string"?

[==P==]


Feb 1 '06 #1
4 1062
Ted
L is Unicode (wide character) string in C++.

Ted.

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
The following line of code:

m_Font = gcnew System::Drawing::Font( L"Arial", 10 ) ;

also works like this:

m_Font = gcnew System::Drawing::Font( "Arial", 10 ) ;

Note that the 'L' in front of "Arial" is missing in the second version.
What is the difference, if any, between L"string" and "string"?

[==P==]


Feb 1 '06 #2
Hi Peter,
The following line of code:

m_Font = gcnew System::Drawing::Font( L"Arial", 10 ) ;

also works like this:

m_Font = gcnew System::Drawing::Font( "Arial", 10 ) ;

Note that the 'L' in front of "Arial" is missing in the second version.
What is the difference, if any, between L"string" and "string"?


Well, the "L" represents a unicode string to the compiler, so it saves a bit
of work. However, neither is optimal in this case. From what I seem to
remember, both will invoke a System::String conversion that converts from an
unmanaged char/wchar_t pointer to a System::String instance (possibly
invoking an encoding conversion), which is totally unnecessary.

Managed C++ actually includes a syntax to ensure you define a literal that
is already a System::String instance and that is subject to all the
interning the runtime uses for this, via de 'S' prefix. So the correct way
really is:

m_Font = gcnew System::Drawing::Font( S"Arial", 10 ) ;

That said, this is unnecessary in C++/CLI, because the compiler can
distinguish the kind of literal from context, I believe, and use a managed
string literal when necessary.
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Feb 1 '06 #3
Hi Tomas!
Managed C++ actually includes a syntax to ensure you define a literal that
is already a System::String instance and that is subject to all the
interning the runtime uses for this, via de 'S' prefix. So the correct way
really is:


Yes. This cas the case in VC7(.1) (managed C++) but in C++/CLI MS
changed this behaviour and now completely ignores the prefix for string
literals in conjunction with System::String

See: Porting and Upgrading: String Literal
http://msdn2.microsoft.com/ms235263

The compiler just converts the string literal to an System::String,
regardless of the prefix.

See: System::String Handling in Visual C++
http://msdn2.microsoft.com/ms177218

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Feb 1 '06 #4
Hi Jochen,
Yes. This cas the case in VC7(.1) (managed C++) but in C++/CLI MS changed
this behaviour and now completely ignores the prefix for string literals
in conjunction with System::String


I think that was what I meant when I said "That said, this is unnecessary in
C++/CLI, because the compiler can
distinguish the kind of literal from context, I believe, and use a managed
string literal when necessary." :)

The reason I mentioned the 'S' was because I got confused thinking the user
was still doing MC++ development. too much language dyslexia :)

Thanks for pointing it out
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Feb 1 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: DavidS | last post by:
Have Visual Studio.NET installed on MS 2000 Professional OS laptop. No issue ever with web development and SQL connections. Purchased new laptop with XP Professional SP2!!!!!!!! & Visual...
22
by: Rob R. Ainscough | last post by:
Sorry to hear about the job cuts and Oracle now out sourcing to India. Rob.
0
by: Ramprasad | last post by:
Life is Different here, sky has no limit but you must grip it with this website, your Mirror of mind are present there. Whatever you want related to your everyday life, it can present or give...
1
by: leighahh | last post by:
Hi everyone i was wondering if there was a way to turn this code that is css into HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
2
by: dibblm | last post by:
I'll start this hopefully simple and add code where needed or requested. Im using a combobox that bound to a DataSet. The Dataset retreives it's values from SQL. I can retreive the values...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.