> Joe, you are commenting on wdffdo.h here. Not on his code, which entirely
invalidates the harangue.
//Daniel
That was not apparent to me. You would not believe how many times I see
this error. Every programmer with marginal C knowledge makes it. After I
explain it to them, I get some of the following
ULONG result;
PULONG presult = &result;
and when I ask why, they tell me the function prototype requires a PULONG
variable!
Certainly the second-worst example was
PULONG result = new ULONG;
…function using result…
…do things with *result
delete result;
and the worst (which was also in C++) wasa
PULONG result = (PULONG)malloc(sizeof(ULONG));
…function using result…
…do things with *result…
free(result);
I would have at least three students per class who did some variant of
these; they did not comprehend the concept of pointers, initialized
variables, or how to read function prototypes. Many of these had more
than a decade of C programming experience, and one complained that he had
found pointers so esoteric that he never understood why anyone would want
to use them [let us not digress into a discussion of
pointers-vs-references, e.g., a Java/C# vs C/C++ discussion…]. With ten
years’ experience, he was also struct-challenged, and the notion of union
was just so much noise. If he wanted an array of multivalued objects, he
would create an array of int, and array of bool, an array of… instead of
declaring a struct and making it an array.
Maybe I’m just frustrated because I have lost six of the last ten days to
illnesses of various sorts, including two hospital stays. But I think
that code as we saw it shows a serious defect in thinking. And the OP
should have spotted that error.
I didn’t think that any of the WDF source was available, so seeing a
newbie mistake like this caused me to think it was the OP’s code. If this
is Microsoft code, some manager somewhere should catch pluperfect hell for
either (a) not catching this or (b) not realizing his programmers were so
undertrained that they could make this kind of error.
In my Advanced Systems Programming course, I even devoted six slides to
this problem, only to have students make the same error on their very
first lab. Some of them just don’t get pointers at all!
joe
>Joe wrote in message news:xxxxx@ntdev…
>
>But it looks like you made one of the silliest possible errors. You read
>the documentation of the function, and it said “PULONG ResultLength”. So
>you assumed you had to have a variable of type PULONG that you would
>passin, which means you have no idea how C works.
>
>The correct way, which you would know if you understood C/C++, would be
>ULONG ResultLength;
>…(WdfDriverGlobals, …, &ResultLength)
>I suggest reading about pointers in C, and fully understand what a
> pointer
>is, and does, and how they are created. &ResultLength creates a PULONG
>referencing the ULONG ResultLength. This is beginner’s C knowledge.
>Learn the language you are programming in. The specification of a type
> of
>an argument to a function DOES NOT MEAN YOU NEED A VARIABLE OF THAT TYPE.
>It means you need an /expression/ of that type. So, for example, if
>ResultLength is a ULONG, the expression &ResultLength is a PULONG. And
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminarsTo unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer