|
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 30 2013 03:20 RoyGBiv_13 wrote:Show nested quote +
Meh, no one's been able to show me exactly why and how C# is better. The only difference between the two is syntax. The fact that there are converters out there that will convert C#.NET to VB.NET and vice versa is strongly suggestive of this.
Not to fuel the C# vs VB sub-thread, I've always found that conversions between between languages is often a hodgepodge of crappy, unreadable syntax. Though I haven't delved too deeply into the .NET framework, so I can't comment on that particular conversion. Are there language converters that don't suck, or is my anecdotal evidence actually a representation of the whole? They should be pretty good I would guess from existence of things like .Net reflector. Since all of them are compiled to the same intermediate language and can be somewhat decompiled I would guess the translation tools should be pretty capable.
|
Hi, im playing around with the Code Analysis tool provided by Visual Studio and noticed the following:
//Foo.h class Foo { public: int& operator [] (unsigned int i); private: int x[3]; };
//Foo.cpp #include "Foo.h"
int& Foo::operator [] (unsigned int i) { return x[i]; }
//main.cpp #include "Foo.h"
int main(void) { int x[3]; x[5]; // this gets detected Foo foo; foo[5]; // this does not int *y = new int; // neither does this (no delete) } Are there any settings i can change to enable the code analysis tool to identify these errors?
|
On January 30 2013 05:40 LukeNukeEm wrote:Hi, im playing around with the Code Analysis tool provided by Visual Studio and noticed the following: //Foo.h class Foo { public: int& operator [] (unsigned int i); private: int x[3]; }; //Foo.cpp #include "Foo.h"
int& Foo::operator [] (unsigned int i) { return x[i]; } //main.cpp #include "Foo.h"
int main(void) { int x[3]; x[5]; // this gets detected Foo foo; foo[5]; // this does not int *y = new int; // neither does this (no delete) } Are there any settings i can change to enable the code analysis tool to identify these errors? Nope but you can use VLD or the Microsoft debug macros for detecting memory leaks.
You can also just use an assert in your index operator since you know the size of the array.
|
On January 30 2013 03:33 tofucake wrote: For some reason, even though both are compiled to MSIL, there are differences in the languages that make some conversions impossible. For instance, trying to sort a ListView by any but the first column in VB.Net isn't possible. Doing it in C# is as simple as calling a function called sortColumn (I think). It's beyond me why that's true, but it is (or at least was a few years ago, the last time I used VB.Net). I don't remember specifics, but I do remember there being nuances of C# that couldn't translate to VB.NET.
The main reason VB.NET gets picked over C# at my PoB has nothing to do with the capabilities of either and almost everything to do with it being "generally more readable" to the layperson or language-inexperienced developer. Welcome to working with the government.
|
Is anyone here familar with GNU radio ? The setup is as following: I want to stream a music / video file with a UDP source (or just a file source) and sink from one computer, over to another computer with a setup with UDP source and sink aswell, and then a media player ( VLC in this case) listening on a specific port, that the UDP sink on the recieving comp sends to. It seems like the custom made GNU radio blocks really aren't that good for recieving data. I made it work with just sending through gnu radio, but recieving directly in VLC through wireless. Does anyone have experience programming blocks for GNU radio, with UDP sources in mind?
|
On January 30 2013 03:45 mcc wrote:I knew that, but trying to answer you forced me to actually look properly at VB.NET. Seems they actually created more of a new language as they fixed the most glaring nonsense from VB. In that case I move VB.Net from category of bad design, to just ugly. It is too verbose and cumbersome and in general the syntax is just strange/ugly. But all that is somewhat subjective so we do not have to argue about it  It still seems to lack some things, like unsafe, but those are just rare cases. I was more arguing about VB and I will stand by what I said about it  Sorry if you felt like I was attacking you! I didn't mean to. It's just that us VB.NET developers get a lot of flack sometimes, so it's a bit of a sore spot. No hard feelings 
Edit: I will say that if you are given a choice (or at least, you don't have any legacy code or grandfathering to pinhole you between one or the either), C# is the better pick simply because it's much easier to translate learned skills, either coming from a background in or moving to C/Java.
|
On January 30 2013 09:11 enigmaticcam wrote:Show nested quote +On January 30 2013 03:45 mcc wrote:I knew that, but trying to answer you forced me to actually look properly at VB.NET. Seems they actually created more of a new language as they fixed the most glaring nonsense from VB. In that case I move VB.Net from category of bad design, to just ugly. It is too verbose and cumbersome and in general the syntax is just strange/ugly. But all that is somewhat subjective so we do not have to argue about it  It still seems to lack some things, like unsafe, but those are just rare cases. I was more arguing about VB and I will stand by what I said about it  Sorry if you felt like I was attacking you! I didn't mean to. It's just that us VB.NET developers get a lot of flack sometimes, so it's a bit of a sore spot. No hard feelings  Edit: I will say that if you are given a choice (or at least, you don't have any legacy code or grandfathering to pinhole you between one or the either), C# is the better pick simply because it's much easier to translate learned skills, either coming from a background in or moving to C/Java. I do not mind aggressive arguments, as I do that myself. And in this case I am happy since without it I might still live under the delusion that VB.Net is basically VB 6.0 just working with .Net libraries, whereas they actually improved the language.
|
Do people implement threads for programs in C? What about C++? I've looked at several tutorials, and I was surprised threading does not come as standard like java.
|
On January 31 2013 09:24 darkness wrote: Do people implement threads for programs in C? What about C++? I've looked at several tutorials, and I was surprised threading does not come as standard like java. It does come as standard as of C++11.
|
On January 31 2013 11:36 Mstring wrote:Show nested quote +On January 31 2013 09:24 darkness wrote: Do people implement threads for programs in C? What about C++? I've looked at several tutorials, and I was surprised threading does not come as standard like java. It does come as standard as of C++11.
Nice one. Thanks. I was disappointed for a bit that I couldn't find any thread support. ^^
|
On January 31 2013 16:32 darkness wrote:Show nested quote +On January 31 2013 11:36 Mstring wrote:On January 31 2013 09:24 darkness wrote: Do people implement threads for programs in C? What about C++? I've looked at several tutorials, and I was surprised threading does not come as standard like java. It does come as standard as of C++11. Nice one. Thanks. I was disappointed for a bit that I couldn't find any thread support. ^^
there are plenty of libraries that provide this. check out boost thread f.ex.
|
Hello I have a big problem with combinatorial operations like generating permutations, combinations and variations (all with and without repetition). Im programming on C#, and I know there are libraries around the internet, that do these stuff, but I want to understand how to implement those operations myself and write my own methods.
I managed to generate all subsets of a set (all Combinations), using a bit mask. It may not be the best way, but I understand what Im doing completely and can modify it to do different stuff with it. Its also easy to limit the size of the subsets. Here is the code (with some lame comments to laugh at :D ) if someone wants to take a look: + Show Spoiler + //this method checks if there is 1 or 0 at the passed index //in the binary representation of the passed input public static byte CheckBitValueII(int input, int index) { int checker = 1 << index;
int result = input & checker;
if (result == checker) { return 1; } else { return 0; }
}
static void Main() { byte n = byte.Parse(Console.ReadLine()); //size of the set
//input the set List<int> itemset = new List<int>(); for (byte i = 0; i < n; i++) { itemset.Add(int.Parse(Console.ReadLine())); }
//list of lists containing int values //this list will contain all the subsets //each subset is a list of integers List<List<int>> allSubsets = new List<List<int>>();
int subsetCount = (int)Math.Pow(2, itemset.Count); //the count of the possible subsets
//we take the number of each of the possible subsets in order to generate them //0 is for the empty subset for (int i = 0; i < subsetCount; i++) { List<int> subset = new List<int>();//a list to contain the generated subset
//we use binary number to generate subsets //since the largest subset is as large as the original input set //the size of the binary number which we will use will be the //same as the size of the input set //the binary number is actually the index of the current //subset we want to generate //we check where in that binary number there are 1 //and we take the items of the input set which are in the same position //(aka index) as the 1 in the binary number for (int bitIndex = 0; bitIndex < itemset.Count; bitIndex++) { if (CheckBitValueII(i, bitIndex) == 1) { subset.Add(itemset[bitIndex]); } }
allSubsets.Add(subset);//the subset is already generated and is now stored //then we go to the number of the next subset and the process repeats itself }
Problem is it does not support repetition. However, variations and permutations are another story. I just cant wrap my brain around a way to generate them at all. And I want to be able to do so with and without repetition. So I hope that here, someone may be able to explain to me how to do this.
|
You mean permutations as in all possible orderings of a set's members?
I haven't done a lot of programming related so set theory, so I haven't the foggiest idea what a standard approach to that problem would be, but the approach that occurs to me would be:
Create N! arrays of length N Take the first (N-1)! arrays: Each array gets your set's first value inserted into it Take the first (N-2)! arrays in this sub-array Each array gets your set's second value inserted into it ... and so on ... and so on
Does that make sense? Have I understood the problem correctly?
|
On January 31 2013 19:41 ZeroReverse wrote:Hello I have a big problem with combinatorial operations like generating permutations, combinations and variations (all with and without repetition). Im programming on C#, and I know there are libraries around the internet, that do these stuff, but I want to understand how to implement those operations myself and write my own methods. I managed to generate all subsets of a set (all Combinations), using a bit mask. It may not be the best way, but I understand what Im doing completely and can modify it to do different stuff with it. Its also easy to limit the size of the subsets. Here is the code (with some lame comments to laugh at :D ) if someone wants to take a look: + Show Spoiler + //this method checks if there is 1 or 0 at the passed index //in the binary representation of the passed input public static byte CheckBitValueII(int input, int index) { int checker = 1 << index;
int result = input & checker;
if (result == checker) { return 1; } else { return 0; }
}
static void Main() { byte n = byte.Parse(Console.ReadLine()); //size of the set
//input the set List<int> itemset = new List<int>(); for (byte i = 0; i < n; i++) { itemset.Add(int.Parse(Console.ReadLine())); }
//list of lists containing int values //this list will contain all the subsets //each subset is a list of integers List<List<int>> allSubsets = new List<List<int>>();
int subsetCount = (int)Math.Pow(2, itemset.Count); //the count of the possible subsets
//we take the number of each of the possible subsets in order to generate them //0 is for the empty subset for (int i = 0; i < subsetCount; i++) { List<int> subset = new List<int>();//a list to contain the generated subset
//we use binary number to generate subsets //since the largest subset is as large as the original input set //the size of the binary number which we will use will be the //same as the size of the input set //the binary number is actually the index of the current //subset we want to generate //we check where in that binary number there are 1 //and we take the items of the input set which are in the same position //(aka index) as the 1 in the binary number for (int bitIndex = 0; bitIndex < itemset.Count; bitIndex++) { if (CheckBitValueII(i, bitIndex) == 1) { subset.Add(itemset[bitIndex] ; } }
allSubsets.Add(subset);//the subset is already generated and is now stored //then we go to the number of the next subset and the process repeats itself }
Problem is it does not support repetition. However, variations and permutations are another story. I just cant wrap my brain around a way to generate them at all. And I want to be able to do so with and without repetition. So I hope that here, someone may be able to explain to me how to do this. Just a short comment. Recently I needed to generate all permutations. In the end I used Steinhaus-Johnson-Trotter algorithm , specifically Even's speedup described on that page. It has some nice properties, like the subsequent permutations differing only by single swap. It is also not hard to understand why it works.
|
A programming puzzle at this year's MIT Mystery hunt made me happy inside.
Halting Problem
+ Show Spoiler +Basically, each of the linked pieces of code would take an infeasible amount of computing time / memory to run in its current language, but it's possible to either work out what the result will end up being, or convert it into a language that could handle the problem effectively.
Having a puzzle that involved Converting C++ into Prolog made me happy.
|
Sup ya'll, im currently busy with a C function thats supposed to copy a matrix to another matrix at another memory adress. So I coded my function and tested it, with both matrix having the same sizes. And right now the code copies fine until the last two values where it just doesnt want to copy them.
void matriscopy (int * destmat, int * srcmat, int rowcount, int columncount) { int i, j; for (i=0; i<rowcount; i=i+1) /* rad-nr */ for (j=0; j<columncount; j=j+1) /* kolumn-nr */ *(destmat+rowcount*i+j) = *(srcmat+rowcount*i+j); }
I'd be very happy if someone could help me out, im also open for feedback to changes for the function that doesnt involve memcopy!
|
On February 01 2013 04:03 omarsito wrote:Sup ya'll, im currently busy with a C function thats supposed to copy a matrix to another matrix at another memory adress. So I coded my function and tested it, with both matrix having the same sizes. And right now the code copies fine until the last two values where it just doesnt want to copy them. void matriscopy (int * destmat, int * srcmat, int rowcount, int columncount) { int i, j; for (i=0; i<rowcount; i=i+1) /* rad-nr */ for (j=0; j<columncount; j=j+1) /* kolumn-nr */ *(destmat+rowcount*i+j) = *(srcmat+rowcount*i+j); }
I'd be very happy if someone could help me out, im also open for feedback to changes for the function that doesnt involve memcopy! This looks fine to me, but is there any particular reason you're doing the pointer math instead of just using them like the arrays they are?
e.g.:
void matrixcopy(int** dest, int** src, int row_count, int col_count) { int row, col; for(row = 0; row < row_count; row++) { for(col = 0; col < col_count; col++) { dest[row][col] = src[row][col]; } } }
|
On February 01 2013 04:29 tec27 wrote:Show nested quote +On February 01 2013 04:03 omarsito wrote:Sup ya'll, im currently busy with a C function thats supposed to copy a matrix to another matrix at another memory adress. So I coded my function and tested it, with both matrix having the same sizes. And right now the code copies fine until the last two values where it just doesnt want to copy them. void matriscopy (int * destmat, int * srcmat, int rowcount, int columncount) { int i, j; for (i=0; i<rowcount; i=i+1) /* rad-nr */ for (j=0; j<columncount; j=j+1) /* kolumn-nr */ *(destmat+rowcount*i+j) = *(srcmat+rowcount*i+j); }
I'd be very happy if someone could help me out, im also open for feedback to changes for the function that doesnt involve memcopy! This looks fine to me, but is there any particular reason you're doing the pointer math instead of just using them like the arrays they are? e.g.: void matrixcopy(int** dest, int** src, int row_count, int col_count) { int row, col; for(row = 0; row < row_count; row++) { for(col = 0; col < col_count; col++) { dest[row][col] = src[row][col]; } } } No particular reason only other then that it felt easier from the beginning. I tried using your solution but I get a segmentation fault when it tries to call the function. Could it be because i call the function with the call matrixcopy(rmat, imat, ROWCOUNT, COLUMNCOUNT); where rmat is the destination matrix and imat source matrix
|
On February 01 2013 02:44 sylverfyre wrote:A programming puzzle at this year's MIT Mystery hunt made me happy inside. Halting Problem+ Show Spoiler +Basically, each of the linked pieces of code would take an infeasible amount of computing time / memory to run in its current language, but it's possible to either work out what the result will end up being, or convert it into a language that could handle the problem effectively.
Having a puzzle that involved Converting C++ into Prolog made me happy. That is the worst C++ code I've ever seen.
And why was it trying to do this at compile time?
|
On February 01 2013 04:03 omarsito wrote:Sup ya'll, im currently busy with a C function thats supposed to copy a matrix to another matrix at another memory adress. So I coded my function and tested it, with both matrix having the same sizes. And right now the code copies fine until the last two values where it just doesnt want to copy them. void matriscopy (int * destmat, int * srcmat, int rowcount, int columncount) { int i, j; for (i=0; i<rowcount; i=i+1) /* rad-nr */ for (j=0; j<columncount; j=j+1) /* kolumn-nr */ *(destmat+rowcount*i+j) = *(srcmat+rowcount*i+j); }
I'd be very happy if someone could help me out, im also open for feedback to changes for the function that doesnt involve memcopy!
Fascinating...
the last *two* values? Is that an entire row, or is just the last two values in the row? Can you share where you are malloc'ing for these data?
I've never gotten that pointer assignment to every work in my own experience, for some reason or another, and I always end up using memcpy. If you want to optimize this a bit, you can use an intermediary 64-bit register if you are running this on your x86-64 pc. The compiler will probably optimize this anyway by unrolling the loop and using a register, but maybe not (you can check the assembly if you're crazy).
void matriscopy (int * destmat, int * srcmat, int rowcount, int columncount) { int i, j; register long temp; for (i=0; i<rowcount; i=i+1) /* rad-nr */ for (j=0; j<columncount; j=j+1) /* kolumn-nr */ *(destmat+rowcount*i+j) = (temp = *(srcmat+rowcount*i+j)); }
|
|
|
|