• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
codingo

Syntax I've never seen before

17 posts in this topic

I'm implementing a licensing api that has lib files written in C (which may have something to do with the exotic syntax). My application is written in C++ and I've never used C before. It looks like this:

License::License(int productID, const wstring version, etc)
{
     d_LicenseFilePath = L"";//?????????????
}

can't make sense of the: L"" value.  Is there a guru out there that knows?

0

Share this post


Link to post
Share on other sites

Though you know that that function is C++, and not C, because it uses std::wstring (the wide char version of std::string).

(It's also definitely a C++ piece of code, because it's in a class constructor).

 

L"" is C++ just as much as L"" is C, so here it wouldn't be considered "intermingling" C and C++, but just C++ code.

 

What I mean to say is, don't think of L"" as 'C'. It's fully C++ even if C also has that feature. C also has variables, but when you encounter variables in C++, you don't think of variables as "Oh, that's a C thing".

0

Share this post


Link to post
Share on other sites

in that sence couldn't you say the same thing about C in its entirety since C++ is a subset of C?

 

Which leads to the question: if "wstring d_LicenseFilePath;" was declared as a private member var of the class, why establish the wstring literal type again in the constructor?

0

Share this post


Link to post
Share on other sites

in that sence couldn't you say the same thing about C in its entirety since C++ is a subset of C?

 

 

What kind of nonsense is that?

 

 

 

 

Very brief history lesson:

 

 

C had many dialects.  The original was written mostly by Dennis Ritchie at Bell labs from 1969-1973. The language was applied in several places and was customized and changed around.  In 1979 there was a book attempting to standardize the language, as K&R C.  The book was written by the two who contributed most to the language at that time.

 

The C++ language was one of the many dialects, called "C with Classes", used internally by AT&T. It was a dialect of the language.

 

Note that "C with Classes" was not a proper subset of K&R C. Even though they shared a common base and most of the trivial K&R C code could be made to compile with it, they were not absolutes.  You could write K&R C programs that would not complile in C with Classes, and you could write C with Classes code that would not compile in K&R C.

 

Even back then, in 1980, neither language was a subset of the other.  

 

In 1983 when the C language began to be standardized by ANSI, the "C with Classes" version was renamed C++.  When C++ compilers hit the public in 1985 the language was a sibling of ANSI C, neither had a subset/superset or parent/child relationship.  They were similar but distinct.

 

The two languages have a similar root from the 1970's, but neither language has ever been a subset of the other.  They are similar, and many constructs are the same, but in no way is C a subset of C++, nor the other way around.  The two languages have always been separate and distinct.

0

Share this post


Link to post
Share on other sites
The two languages have always been separate and distinct.

ok, I was lead to believe that C++ was a direct derivation of C.

 

That threw me off as well as the idea that C and C++ get along so well and that I had never seen that syntax style before. 

 

But really, why re-establish the data type within the constructor method when the data type was determined in the declaration?

0

Share this post


Link to post
Share on other sites

Because the right hand side of an assignment needs to be a compatible type with the left hand side of an assignment. Just as you can't assign an int to a string, you can't assign a regular string literal to a wstring.

0

Share this post


Link to post
Share on other sites

ok to summ it all up, please correct me if I am wrong.
 

wstring d_LicenseFilePath;

declares a wide string var...

L""

marks the string literal L as a wide character string literal and...

d_LicenseFilePath = L""

assigns the value L to "d_LicenseFilePath" var which contains only wide string literals

0

Share this post


Link to post
Share on other sites

in that sence couldn't you say the same thing about C in its entirety since C++ is a subset of C?

Even though alot of C syntax compiles properly in C++, some stuff isn't used in the common everyday C++ that is more common among C users. The stuff that, while functional in C++, isn't normally used (purely subjectively on my part), I tend to think of as more for 'C' backwards compatibility.

For example:

typedef struct MyStruct
{
    //...
};

What is the 'typedef' there for? In C++, normally, unless you're being backwards compatible, you just type 'struct MyStruct'.

 

Again, subjective on my part. My only point is that L"" isn't there just for backwards compatibility with C, it's there because you need to be able to define wide-character literals in C++ during normal C++ usage (if you need wide characters).

 

"string literal" becomes const char*

L"string literal" becomes a const wchar_t*

 

Since they are different types, you can't (and shouldn't be able to, to avoid errors) assign a const char* to a std::wstring, so if you wanted to, within your code, assign a literal to a wstring (or to a wchar_t pointer), you'd need some way to create literals of that type, and that's what the L prefix is for.

 

In C++11, two more string types were defined:

std::u16string, which manages strings composed of char16_t*.

You can declare raw char16_t string literals like this: u"string literal"  (a const char16_t*)

 

std::u32string, which manages strings composed of char32_t*.

You can declare raw char32_t string literals like this: U"string literal"  (a const char32_t*)
 

Which leads to the question: if "wstring d_LicenseFilePath;" was declared as a private member var of the class, why establish the wstring literal type again in the constructor?

You're correct that 'd_LicenseFilePath' was already initialized to an empty string by default, so that redundant initialization isn't necessary.

0

Share this post


Link to post
Share on other sites

ok to summ it all up, please correct me if I am wrong.
 

wstring d_LicenseFilePath;
declares a wide string var...

Yes, it defines a std::string-like class that takes wchar_t* instead of char*.
Both std::string and std::wstring are just typedefs of the template class std::basic_string.

L""
marks the string literal L as a wide character string literal and...

Yep.

d_LicenseFilePath = L""
assigns the value L to "d_LicenseFilePath" var which contains only wide string literals

The 'L' isn't anything except to tell the compiler that the following string literal is to be a const wchar_t* instead of const char*.
L"" is the same as "", except in wide characters.
L"Meow" is the same as "Meow", except in wide characters.

L"" is an empty wchar_t* string. The L isn't any part of the string itself.
0

Share this post


Link to post
Share on other sites

oh i c, thank you Servant of the Lord. In other words: A redundancy of no perceivable consequence:)

0

Share this post


Link to post
Share on other sites

Thank you Servant of the Lord. I'm starting a Knights of St. John chapter. If you would like to join, just wish it so:)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0