|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On January 06 2013 03:39 netherh wrote:Show nested quote +On January 06 2013 03:09 heishe wrote:
Sorry, but if you need a review of something that basic, you should fail those interview questions. I hope you didn't say that you have experience working with C++, or knowledge of C++, or something like that in your application, because that would be a lie.
That's pretty harsh - he's looking for a review of something that shouldn't really be used in modern C++ because of how icky it is. Show nested quote + char *chararray = "hello"; //this is just a short way of writing the following code: //char *chararray = new char[6]; chararray[3] = 's'; //the entire string is now "helso"
For example, I think this is actually wrong. IIRC "hello" is a string literal - a const char* stored statically, not in memory allocated with new. This means that trying to change a character like that is actually undefined behaviour...
Ye, it's a const char*, you need a const_cast<char*> at least, and that's definitely undefined behaviour.
|
LOL at the bike post. wtf.
|
On January 06 2013 09:01 heishe wrote:Show nested quote +On January 06 2013 03:39 netherh wrote:On January 06 2013 03:09 heishe wrote:
Sorry, but if you need a review of something that basic, you should fail those interview questions. I hope you didn't say that you have experience working with C++, or knowledge of C++, or something like that in your application, because that would be a lie.
That's pretty harsh - he's looking for a review of something that shouldn't really be used in modern C++ because of how icky it is. char *chararray = "hello"; //this is just a short way of writing the following code: //char *chararray = new char[6]; chararray[3] = 's'; //the entire string is now "helso"
For example, I think this is actually wrong. IIRC "hello" is a string literal - a const char* stored statically, not in memory allocated with new. This means that trying to change a character like that is actually undefined behaviour... Well, it compiles like that. I'm not even sure if the standard says that changing the value of a constant (e.g. via const_cast) is undefined behavior. Either way, on all machines that you can get this code to compile on, it will run without problems or unexpected behavior, because statically stored things don't get stored any differently than stuff that is created on the heap. It's still just some address in memory space. Of course if you were to create the array using new, the locations of the two arrays would be different: One would be "above the stack" where static stuff like that is usually allocated, and the other would be somewhere in heap memory. I just wanted to illustrate what "hello" does in terms of functionality.
It's compiler dependent I'm sure, but in MSVC the string literal is stored in a global read-only data section. When you run that code, you get an access violation. I guess part of the reason it's read-only is that MSVC will reuse global string literals if possible. For example in this code:
char * ptr1 = "Lol"; char * ptr2 = "Lol";
ptr1 and ptr2 will point to the same memory address.
Another interesting case you didn't mention is something like this:
char ptr1[4] = "Lol"; //same as char ptr1[4] = { 'L', 'o', 'l', '\0' }; which is also the same as char ptr1[4] = { 'L', 'o', 'l' }; char * ptr2 = ptr1; char * ptr3 = &ptr1;
In this case, the string is stored on the stack. So with your 2 examples, the string can be stored on the stack, heap, or some static location. Another interesting thing to note is that the type is not actually a pointer, the type is "char[4]". Whenever you use the variable though, it generally will automatically decay into a pointer. A fun case where it doesn't decay automatically is the 3rd line. It does on the 2nd line though, so ptr2 and ptr3 are actually the same.
EDIT:
Just for fun I ran this code:
int main() { char * str1 = "Lol"; char * str2 = "Lol"; DWORD old_protect;
VirtualProtect(str1, strlen(str1) + 1, PAGE_READWRITE, &old_protect);
printf("%s\n%s\n", str1, str2);
str1[1] = 'a';
printf("%s\n%s\n", str1, str2); return 0; }
and got:
Lol Lol Lal Lal
as expected.
I also tried it with str1 and str2 set like this:
char * str1 = "Lol"; char * str2 = "LolLol";
I was hoping that MSVC would optimize and set str1 to point into the middle of str2, but no such luck. 
|
How did I miss that TL had this kind of thread?
I love programming. In high-school, I read Java for two years and I'm currently in university studying game design and programming, where we are reading C++ and SDL at the moment. I also got one book on Perl and one on Android as Christmas present.
--- I'm wondering one thing about Visual Studio 2010 on 64-bit Windows 7. Have anyone experienced that it might freeze when you run a C++ program in debug-mode and you legitimately end it? Had happened for me two days in a row now.
(I'm using VC2010 because my current programming teacher told us to)
|
On January 08 2013 00:28 WindWolf wrote: How did I miss that TL had this kind of thread?
I love programming. In high-school, I read Java for two years and I'm currently in university studying game design and programming, where we are reading C++ and SDL at the moment. I also got one book on Perl and one on Android as Christmas present.
--- I'm wondering one thing about Visual Studio 2010 on 64-bit Windows 7. Have anyone experienced that it might freeze when you run a C++ program in debug-mode and you legitimately end it? Had happened for me two days in a row now.
(I'm using VC2010 because my current programming teacher told us to)
What do you mean legitimately end it? It tends to freeze up for a bit if you close it by hitting the "X". If you hit the stop button (or hit Shift+F5), it will exit more quickly.
|
On January 08 2013 01:08 waxypants wrote:Show nested quote +On January 08 2013 00:28 WindWolf wrote: How did I miss that TL had this kind of thread?
I love programming. In high-school, I read Java for two years and I'm currently in university studying game design and programming, where we are reading C++ and SDL at the moment. I also got one book on Perl and one on Android as Christmas present.
--- I'm wondering one thing about Visual Studio 2010 on 64-bit Windows 7. Have anyone experienced that it might freeze when you run a C++ program in debug-mode and you legitimately end it? Had happened for me two days in a row now.
(I'm using VC2010 because my current programming teacher told us to) What do you mean legitimately end it? It tends to freeze up for a bit if you close it by hitting the "X". If you hit the stop button (or hit Shift+F5), it will exit more quickly. Sorry, wasn't clear enough In short, I have been writing a simple SDL-game where the game automatically ends if the player's character collides with a certain kind of enemy. Then it exits the main game loop, clear up all resources and if you beat the high-score, it asks you to fill in your name which it writes to a txt-file
And by freezing, I meant that the entire VC becomes unresponsive
|
Hi everyone, i have a question for you ( it's just a curiosity ): Do your teachers still teach Pascal in high-school? Because in italy they do and i don't know if it is a bad or a good thing. I know Pascal is a very good/easy languge at the beginning but nowadays there are a lot of better languages (Like phyton) that aren't that hard even for beginners
|
My high school did BASIC when I was there and then migrated to VB.NET.
|
On January 08 2013 09:20 stichtom wrote: Hi everyone, i have a question for you ( it's just a curiosity ): Do your teachers still teach Pascal in high-school? Because in italy they do and i don't know if it is a bad or a good thing. I know Pascal is a very good/easy languge at the beginning but nowadays there are a lot of better languages (Like phyton) that aren't that hard even for beginners
Don't sweat the small stuff. Everybody learned something they didn't like when they started. If you go far enough, you'll realize how important learning Pascal was (in some way or another).
Work on some Python stuff outside school if you think you might enjoy it. Then think about the differences between Python and Pascal.
On January 06 2013 03:39 netherh wrote:Show nested quote +On January 06 2013 03:09 heishe wrote:
Sorry, but if you need a review of something that basic, you should fail those interview questions. I hope you didn't say that you have experience working with C++, or knowledge of C++, or something like that in your application, because that would be a lie.
That's pretty harsh - he's looking for a review of something that shouldn't really be used in modern C++ because of how icky it is.
Pointers aren't "icky" just because C++ and similar languages manage them for you. You should understand them because they're fundamental to everything that every programming language (and every computer) does. If you need to review them and don't have your own resources lined up, you probably didn't understand them in the first place. Which is exactly what things like "modern C++" get you. I wouldn't want to hire someone who only learned about pointers so they could slip through my interview process unnoticed, because they're going to eventually make a big mess and cost me more money than they're worth.
|
On January 08 2013 09:44 yeastiality wrote:Show nested quote +On January 06 2013 03:39 netherh wrote:On January 06 2013 03:09 heishe wrote:
Sorry, but if you need a review of something that basic, you should fail those interview questions. I hope you didn't say that you have experience working with C++, or knowledge of C++, or something like that in your application, because that would be a lie.
That's pretty harsh - he's looking for a review of something that shouldn't really be used in modern C++ because of how icky it is. Pointers aren't "icky" just because C++ and similar languages manage them for you. You should understand them because they're fundamental to everything that every programming language (and every computer) does. If you need to review them and don't have your own resources lined up, you probably didn't understand them in the first place. Which is exactly what things like "modern C++" get you. I wouldn't want to hire someone who only learned about pointers so they could slip through my interview process unnoticed, because they're going to eventually make a big mess and cost me more money than they're worth.
Remember that the context here is "const char*", not just "pointers" as a subject. Unless you're working with legacy code or a code base that requires compatibility with C, you probably shouldn't be using such ugly things. There's a good chance he is, but if people are starting new projects that don't need special attention due to hardware constraints/whatever, I think it's best to avoid them.
|
is there a way in jquery where it counts the number of td's in a table and creates a new row if it exceeds a certain number? my submenu items always 'spills' when it exceeds 4 items. I want jquery to move it to another row if it exceeds 4.
from + Show Spoiler + <table class="mainTable"> <tr> <td>ITEM</td><td>ITEM</td><td>ITEM</td><td>ITEM</td><td>ITEM</td> </tr> </table>
to + Show Spoiler + <table class="mainTable"> <tr> <td>ITEM</td><td>ITEM</td><td>ITEM</td><td>ITEM</td> </tr> <tr> <td>ITEM</td> </tr> </table>
so far I have created a jquery function that alerts me the number of td's in a table (as a counter)
+ Show Spoiler + <script> function getBody(element) { var originalTable = element.clone(); var tds = $(originalTable).children('tbody').children('tr').children('td').length; alert(tds); }
getBody($('table.mainTable')); </script>
EDIT: YEY GHOST!
|
On January 08 2013 10:16 Zeke50100 wrote:Show nested quote +On January 08 2013 09:44 yeastiality wrote:On January 06 2013 03:39 netherh wrote:On January 06 2013 03:09 heishe wrote:
Sorry, but if you need a review of something that basic, you should fail those interview questions. I hope you didn't say that you have experience working with C++, or knowledge of C++, or something like that in your application, because that would be a lie.
That's pretty harsh - he's looking for a review of something that shouldn't really be used in modern C++ because of how icky it is. Pointers aren't "icky" just because C++ and similar languages manage them for you. You should understand them because they're fundamental to everything that every programming language (and every computer) does. If you need to review them and don't have your own resources lined up, you probably didn't understand them in the first place. Which is exactly what things like "modern C++" get you. I wouldn't want to hire someone who only learned about pointers so they could slip through my interview process unnoticed, because they're going to eventually make a big mess and cost me more money than they're worth. Remember that the context here is "const char*", not just "pointers" as a subject. Unless you're working with legacy code or a code base that requires compatibility with C, you probably shouldn't be using such ugly things. There's a good chance he is, but if people are starting new projects that don't need special attention due to hardware constraints/whatever, I think it's best to avoid them.
My point when I said that he should fail those questions is that he shouldn't succeed at those questions because if he doesn't understand something as trivial as "char pointers" now, he probably never did (even though he said that he used to do C++ but usage of TorqueScript has "deteriorated" his C++ knowledge, which is BS. There was a period of time when I didn't so much as touch C++ for almost two years, but something as fundamental as anything that has to do with pointers doesn't "deteriorate"), which means that he has little to no actual C/C++ experience. That's exactly what the interviewer would want to know with such questions, not if the candidate was smart enough to look something up in Google in order to answer interview questions.
If it sounded harsh, well - I don't think there's a nicer way to put it. This kind of "learning for interview questions" that everyone employs kind of annoys me. You're trying to fool your employer that you have experience where you really have none.
|
On January 08 2013 17:56 icystorage wrote:is there a way in jquery where it counts the number of td's in a table and creates a new row if it exceeds a certain number? my submenu items always 'spills' when it exceeds 4 items. I want jquery to move it to another row if it exceeds 4. from + Show Spoiler + <table class="mainTable"> <tr> <td>ITEM</td><td>ITEM</td><td>ITEM</td><td>ITEM</td><td>ITEM</td> </tr> </table>
to + Show Spoiler + <table class="mainTable"> <tr> <td>ITEM</td><td>ITEM</td><td>ITEM</td><td>ITEM</td> </tr> <tr> <td>ITEM</td> </tr> </table>
so far I have created a jquery function that alerts me the number of td's in a table (as a counter) + Show Spoiler + <script> function getBody(element) { var originalTable = element.clone(); var tds = $(originalTable).children('tbody').children('tr').children('td').length; alert(tds); }
getBody($('table.mainTable')); </script>
EDIT: YEY GHOST! There's not a native jQuery function that does what you're describing, but it's fairly simple to write one. Try this fiddle for an example: http://jsfiddle.net/rvM4d/1/
Is it clear to you how that works?
|
OMG! THANK YOU SO MUCH! i just started learning jquery. I didn't know it would be that simple. I have to familiarize jquery more.
|
On January 08 2013 18:33 icystorage wrote: OMG! THANK YOU SO MUCH! i just started learning jquery. I didn't know it would be that simple. I have to familiarize jquery more. http://docs.jquery.com/Main_Page
Learn it. Love it. Live it.
I've been programming with jQuery as a significant portion of my job for three years, and I still spend time almost every day reading the jQuery docs. It's essentially another programming language that you use embedded in Javascript. I especially recommend the "selectors" and "manipulation" sections linked at the left under "API" - I still read through them start to finish every once in a while, and I almost always discover something I hadn't realized before that makes my life easier.
|
On January 08 2013 18:33 icystorage wrote: OMG! THANK YOU SO MUCH! i just started learning jquery. I didn't know it would be that simple. I have to familiarize jquery more.
Why don't you just use something like:
<div style="width: ..."> <div style="float: left; width: ...px;">Item 1</div> <div style="float: left; width: ...px;">Item 2</div> <div style="float: left; width: ...px;">Item 3</div> <div style="float: left; width: ...px;">Item 4</div> <div style="float: left; width: ...px;">Item 5</div> ... </div>
The inner divs automatically break into the next row when they don't fit anymore. No javascript needed.
|
Does it apply to tables?
EDIT: okay i tried it
i set my table width to 100% then the table td width to 25%, float left. apparently it only fits 3 cells in the row. if i dont float it left it fits 4 cells.
|
On January 08 2013 18:50 icystorage wrote: Does it apply to tables?
You can put tables in there as float left but it doesn't work with tr/td. Do you NEED to have it as a table considering that tables purely for layout are quite outdated?
|
i set my table width to 100% then the table td width to 25%, float left. apparently it only fits 3 cells in the row. if i dont float it left it fits 4 cells.
Yes I probably need to since I invested a lot of time using tables for a layout
|
On January 08 2013 19:04 icystorage wrote:
i set my table width to 100% then the table td width to 25%, float left. apparently it only fits 3 cells in the row. if i dont float it left it fits 4 cells.
Yes I probably need to since I invested a lot of time using tables for a layout Seriously, you should invest some more time in learning how to not use tables for layout. I didn't really give it any thought before because I was just trying to help you understand how to use jQuery, but using tables to do anything but display tabulated data is major bad mojo. There is almost nothing that you can achieve with a table that isn't possible with nested divs, and my experience has been that working with tables is a maintenance nightmare.
|
|
|
|