|
OK, that's one of the things I never install. Fair enough, glad you were around to call me on it
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
I saw that there are some articles on writing device drivers using C++ but I can't seem to find anything on writing device drivers using C#, even on Google. Is doing this possible? Anyone know where I should look to start?
Thanks in Advance
--Peter
|
|
|
|
|
AFAIK, device drivers need to be written in native code which C++ qualifies and C# doesn't.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
AFAIK that is correct, drivers and kernel stuff require unmanaged code only.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
AFAIK and IMHO, it is great that you confirmed what I said.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
My pleasure.
It will be a while before a Windows Operating System could be written entirely in managed
code; one of the problems is the unpredictable (hence not real-time oriented)
behavior of garbage collection.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Yeah, the word "real-time" is the key. With the overhead of the safe and reliable coding of the managed languages, they will be only suited for application/web programming.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
So if you're taking a course in C#, it's a good thing of they also mention unmanaged code, and tell you how to use that in C#, or else many doors stay closed?
|
|
|
|
|
Well, it depends on your goals and objectives. If you want to be mostly an application or web application programmer, C#, VB.NET and Java are well suited for that job. However, in some real-world situations, you cannot avoid programming in native code such as C and C++. From my experience, most of my coding with managed code required reporting data from the "secondary" source such as an Oracle Server. I use native (unmanaged code) to obtain real-time data from a primary source such as a machine or gage on the plant floor.
In a nutshell, knowing both managed and native languages means you are a more flexible and resourceful programmer. However, you also need to understand or be familiar with your programming enviroment to apply your programming skills. Thus, understanding what is going on underneath (WIN32) the Window Forms application, will foster creative ideas on how to go beyond what .NET is allowing you to do. Many a time, a customer has asked me to do something which .NET does not directly support out of the box, and, usually, I have to go back to the native environment and the required native coding.
I hope there is a message somewhere up there!
George
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
P.S. IMHO, I think the GC manages memory a lot like NTFS does a hard drive. If you have a lot of small and big files, and a lot of files are being added and deleted, if a file does not fit into a current empty spot. Instead of moving files around to make room (time consuming), it will place it in the biggest void of the hard drive.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Can any one please explain me what exactly the below code is doing. I know its replace function but i am not getting it...may be a long gap from programming... ~ ?
<br />
public static void Replace(ref byte b, int pos, byte value)<br />
{<br />
b = (byte)(value == 1 ? b | (1 << pos) : b & ~(1 << pos));<br />
}<br />
Thanks
James
|
|
|
|
|
Hi,
what is the problem, don't you own a book on C#?
and can't you run the code?
then split the line in a couple of lines and look at intermediate values?
this is a normal assignment statement that modifies the content of b
by either setting one bit in it, or clearing one bit in it.
if value equals 1 it ORs b with 1<<pos which="" is="" bit="" number="" "pos"="" (zero-based="" counting
from="" right="" to="" left);="" otherwise="" it="" ands="" with="" the="" logical="" complement="" of="" same.
if="" you="" want="" do="" some="" real="" programming,="" i="" suggest="" hold="" your="" own="" spoon,
and="" feed="" yourself="" as="" much="" possible.
=""
<div="" class="ForumSig">Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Sorry Luc Pattyn,
I am a little slow in answering! I like that spoon saying.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Pssst... there is no spoon.
|
|
|
|
|
You dirty bird!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
This information is well documented. Anyway, ?: is a conditional operator:
condition ? (first_expression) : (second_expression)
where the first_expression is returned when condition is true else the second_expression is returned. The condition is (value == 1). The first_expression is (b | (1 << pos)) where b is being operated on by bitwise OR with 2pos. The second_expression is (b & (1 << pos) where b is being operated on by bitwise AND with the bitwise complement of 2pos. The result type of both expressions is an integer type and needs to be casted to a byte.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
The code looks like it was written by someone who thought himself clever.
Perhaps the code would be clearer as:
public static void Replace(ref byte b, int pos, byte value)
{
byte temp = (byte) ( 1 << pos ) ;
if ( value == 1 )
{
b |= temp ;
}
else
{
b &= ~temp ;
}
}
Though that still doesn't explain the purpose of the routine, and its name.
|
|
|
|
|
PIEBALDconsult wrote: Though that still doesn't explain the purpose of the routine, and its name.
Actually, the purpose was to confuse with clever code.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I want that after the last no. I should get a fullstop and not a comma.
Pl somebody correct my code for me.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ch11Ex03yield
{
public class Primes
{
private long min;
public long max;
public Primes()
: this(2, 100)
{
}
public Primes(long i, long j)
{
if (i < 2)
{
min = 2;
}
min = i;
max = j;
}
public IEnumerator GetEnumerator()
{
for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
{
bool isPrime = true;
for (long possibleFactor = 2; possibleFactor <=
(long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
{
long remainderAfterDivision = possiblePrime % possibleFactor;
if (remainderAfterDivision == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
yield return possiblePrime;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
Console.Write("{0}{1} ",i,
(i==myPrimes.max )?".":",");
Console.ReadKey();
}
}
}
|
|
|
|
|
Calculating the end is expensive but, you always know when it starts.
class Program
{
static void Main(string[] args)
{
bool isFirst = true;
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
{
if (isFirst)
{
Console.Write(i.ToString());
isFirst = false;
}
else
{
Console.Write(", {0}",i.ToString());
}
}
if (!isFirst) Console.Write(".");
Console.ReadKey();
}
}
|
|
|
|
|
humayunlalzad wrote: (i==myPrimes.max )?".":",");
I would do this one of two ways
1 - write the first prime without a comma, then write them all with a leading comma. This means not using foreach, just a for loop.
2 - write the whole thing using a string builder, then use string mashing to remove/replace the last comma before writing to the console.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Did you read my response from when you posted this earlier?
|
|
|
|
|
I didn't spot that he's asking this over and over.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I notice a bug in you constructor: public Primes(long i, long j)
when called with i < 2 min will NOT be set to 2.
Philip Painter
|
|
|
|