Re: Seeting malloc pointer to NULL [2] -Totally confused!!!!!



Could this be my problem,

mallocs's prototype is:

*int8 malloc(int8 size)

?????

--
Best regards
Robert


"Robby" wrote:

Hello Igor and Scott! Thanks for your much appreciated replies!

Yes ! I tried the same thing:

*obj_PASSCODE = (PASSCODE*)malloc(sizeof (PASSCODE));

and made all the assigments like so:

(*obj_PASSCODE)->TOUCHES = TOUCHES;

and it works in VC++, but it doesn't work in my MCU compiler, I think it
could be a limitation... I'm not sure, I could be wrong, but in VC++ it works
perfectly, I am able to retrieve the structure's data even in main after its
been set in config(). And the obj_PASSCODE value is reset to 0 after the call
to:

config(e_FREE, &obj_PASSCODE);

Igor, Ilike the idea of doing it with three seperate functions, however if I
have 30 of these configs in my project, this means I will have 90 functions
as opposed to 20. This is my only pet peave. I greatly respect your input, so
what do you think?

So now that I have gotten it to work in the VC++ compiler, I guess the
problem is on my side as to weather its a specific limitaion in my MCU
compiler... mayby my compiler doesn't support pointers to pointers!

Thanks guys, again this post is getting long, so I will let you know what
happens in another post... I sure hope I will eventually get to the bottom of
this!


--
Best regards
Roberto


"Igor Tandetnik" wrote:

"Robby" <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:213AA21B-76AF-4503-B80F-D0C9307F185B@xxxxxxxxxxxxx
Okay, I have entered the code in VC++ and an error points to the same
line of code:

*obj_PASSCODE = malloc (sizeof (PASSCODE));

The error is:

c:\_DTS_PROGRAMMING\C_PROGRAMMING\c\TEST_4\Test_1.cpp(70): error
C2440: 'type cast' : cannot convert from 'void *' to 'PASSCODE'

malloc() returns void*. Unlike C, there's no implicit conversion in C++
from void* to other pointer types. If you want this code to be valid C++
as well as C, make it

*obj_PASSCODE = (PASSCODE*)malloc(sizeof (PASSCODE));

--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



.



Relevant Pages

  • Re: Garbage collection
    ... void fn{ ... void* const buf1 = malloc; ... If compiler can detect that 'fne' does not cache a pointer somewhere, it can possibly detect that 'buf1' goes out of scope at 'L2'. ... Some GC implementations that will actually scan the stack of all application threads for pointers into its managed heaps, and attempt to follow all the links to NULL. ...
    (comp.lang.c)
  • Re: Scheme and libraries -- piggyback on Java?
    ... pointers to be assigned to other pointer types without casting. ... I suppose I did know at one time that void* was convertible without ... I also just realized that I haven't used an actual C compiler since ...
    (comp.lang.scheme)
  • Re: Is __int64 dead?
    ... Note also that while the compiler can implement native types efficiently, ... It makes very little sense to anyone on an architecture on which pointers ... Well, all pointers are convertible to void*, so make INT_PTR an integer ...
    (microsoft.public.vc.mfc)
  • Re: /DELAYLOAD Linux counterpart for shared objects
    ... A big disadvantage is that the compiler, ... pointers and makes sure the library is there). ... void, ... ub2 charset, ub2 ncharset); ...
    (comp.os.linux.development.apps)
  • Re: Learning to use PICS
    ... john jardine wrote in message ... It supports pointers like "C" but unlike many C compilers for the PIC it ... compiler trap silly errors and generate better code. ... Regards ...
    (sci.electronics.basics)