Link Bar

Home | Games | Programming | Tutorials | Donate | Legal (These are mostly empty right now. Placeholders!)

warning code

This website contains adult content.

Tuesday, February 28, 2012

Day 12: Poking around the internets.

Zach left a helpful link in a comment on yesterday's post, and after reading through the whole thing, I have a slightly clearer idea of what's going wrong.  See, line 187 says:
wcx.lpszClassName=WINDOWCLASS;
...and the error returned is:
error C2440: '=' : cannot convert from 'const char [7]' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
So, OK, at least that's not gibberish to me any more.  And way, way back up in line 15, when I wrote:
#define WINDOWCLASS "Fetris"
...that must have made "WINDOWCLASS" into a constant.  OK.  And on line 187, I'm not certain what that "wcx" bit is all about, but "lpsz" means that I'm setting a long pointer to a null-terminated string - so it wants ASCII.  Right?  But... if it's trying to use a long pointer to a constant wide string... that means it wants Unicode.  So I'm telling the machine to do something with ASCII, and it's trying to do it in Unicode, and that's the problem?  I think so.

I don't know how to fix that, though.  Either I need to do something different in the WinMain function (which I'm not sure what that would be), or I need to change my definition up at the top (and I'm not sure how I ought to do that).  Well, this is what I get for using someone's code from over eight years ago.  And holy carp, I spent over half an hour just typing out the above.  Well, more like five minutes typing and revising it, and 25 minutes cradling my head trying to sort everything out.  This is in addition to the hour I spent poking and prodding and reading and trying to make it work.  And I'm still probably missing something (like a real programming course).  Fine.

I'm going to play around with that NAND to Tetris thing.

Got the hardware simulator running after installing the 64-bit version of Java (had to consult their forums to find out I needed to do that - apparently the version I had before wasn't good enough).  Got the Hardware Simulator running, and figured out how to load and test gates/chips in it.  Nice.  Project 00 complete, on to Chapter 1!

I started flipping through the slides for the lecture, figuring I'd read the chapter after I got an idea of what I'll be learning.  Right away, multiplexers stumped me (well, on slide 9 of 24, anyway).  I could not for the life of me figure out what was going on in that truth table.  Wikipedia to the rescue!  (By the way, is Wikipedia being wonky for anyone else lately?)  Man, multiplexers are easy once you know that the selector picks which input gets to be translated into output!  (I did not know that more than five minutes ago.)  The rest of the slide show was easy after that - but now I have to basically re-learn all of my logic using NAND only, which is doable, but confusing.  Whatever, that's the point of the exercise.

Reading the chapter itself, I further learned what the "canonical representation" of a Boolean function is (it's the inclusive disjunction of all the possible values which yield "true" on the truth table).  I've also got the hardware description language (HDL) down.  See, twenty minutes ago, this was gibberish to me:
/* Xor (exclusive or) gate:If a<>b out=1 else out=0. */  
CHIP Xor {
IN a, b;
OUT out;
PARTS:
Not(in=a, out=nota);
Not(in=b, out=notb);
And(a=a, b=notb, out=w1);
And(a=nota, b=b, out=w2);
Or(a=w1, b=w2, out=out);
}
But now I get it!  See:
/* Xor (exclusive or) gate:
If a<>b out=1 else out=0. */
CHIP Xor { //we have a chip, called "Xor"
IN a, b; // it has inputs "a" and "b"
OUT out; // it has output "out"
PARTS: // these are its parts
Not(in=a, out=nota); // A "not" gate with input from a, outputting to "nota"
Not(in=b, out=notb); // A "not" gate with input from b, outputting to "notb"
And(a=a, b=notb, out=w1); // An "and" gate with input from a and notb, outputting to "w1"
And(a=nota, b=b, out=w2); // An "and" gate with input from nota and b, outputting to "w2"
Or(a=w1, b=w2, out=out); // An "or" gate with input from w1 and w2, outputting to "out"
}
I feel smarter already!

OK, I've been doing this for hours, I'm halfway through the first chapter, and this is like a week's worth of work anyway.  My brain is full.  G'night, everybody!

4 comments:

  1. replace:

    wcx.lpszClassName=WINDOWCLASS;

    with:

    wcx.lpszClassName = wstring(L"Fetris");

    see: http://msdn.microsoft.com/en-us/library/wt3s3k55(v=vs.80).aspx along with my link from yesterday.

    ReplyDelete
  2. error C3861: 'wstring': identifier not found

    I bet I need to define/include something at the beginning to fix this, but I am not sure what.

    ReplyDelete
  3. okay, so. there's this thing called namespaces that allow you to define where functions live, so that you can technically have multiple functions with the same name. Why is this good? I don't know.

    wstring is part of the standard template library, or STL. It resides in the default "string" header. If you want to use wstring, you must first #include . But wstring is not just a random class that exists! NO, it exists, like ALL standard template library classes and functions, under the 'std' namespace.

    SO. If you get that error, there are two ways to fix it:

    1.) preface your wstring references with std::, so you have std::wstring. The double-semicolon is called the "scope resolution operator" and allows you to define what scope (where in the code) things live. std::wstring means "the wstring that exists under the std namespace".

    2.) Earlier in your code, include the line "using namespace std;". This tells the compiler that whenever it can't find a thing to automatically try the namespace std. So if you use 'wstring' what will happen is that it won't be found (it's not defined locally), so it will try std::wstring and it will find it!

    Duuuuude. Next time you have problems text or mail me, I'd love to help more with this :)

    ReplyDelete
  4. I tried both 1 and 2; they returned the following errors:

    1>c:\users\d\documents\visual studio 2010\projects\fetris\fetris\main.cpp(191): error C2039: 'wstring' : is not a member of 'std'
    1>c:\users\d\documents\visual studio 2010\projects\fetris\fetris\main.cpp(191): error C3861: 'wstring': identifier not found

    This is starting to remind me of SMBC's long distance tech support, heh heh. I'll hit you up tomorrow some time for a live session. Thanks again for all your help; have a great one!

    ReplyDelete