Three stupid C questions

Discussion in 'C Programming' started by Jean-Claude ROVIER, Aug 31, 2010.

  1. Hi All,

    I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
    world.
    Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
    any suggestions :) ) and start learning C/C++, I need to translate a C
    prog into TP.

    Here are the supid questions:

    1st:

    I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
    is.
    If the program does 'MyPointer = p++' what does this mean?

    1) MyPointer = p; increment p of 1;
    2) MyPointer = p; Increment p of SizeOf(CStruct);
    3) increment p of 1; MyPointer = p;
    4) increment p op SizeOf(CStruct); MyPointer = p;
    5) something else?

    Second stupid question:

    'if !(a = b)' means

    1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
    '=')
    2) a=b and if b=0 then....
    3) something else?

    Third stupid question:

    When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
    couldn't find the 'dealloc' function in the prog.

    If someone knows where to find basic c++ help (*.hlp, *.doc,...) on the
    net...

    Thanks a lot for your help, and please excuse the stupidity of my
    questions.
    Jean-Claude ROVIER, Aug 31, 2010
    #1
    1. Advertising

  2. Jean-Claude ROVIER

    Seebs Guest

    On 2010-08-31, Jean-Claude ROVIER <> wrote:
    > I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
    > world.


    What's that?

    > Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
    > any suggestions :) )


    djgpp or whatever they call it these days. Free. Pretty good.

    > and start learning C/C++,


    C and C++ are two different languages. Pick one.

    > Here are the supid questions:


    > 1st:


    > I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
    > is.
    > If the program does 'MyPointer = p++' what does this mean?


    I have no idea what you're writing here.

    In general, "x = p++", in C, means the same as:
    x = p;
    p = p + 1;

    That is to say, x is assigned the previous value of p, and p is incremented.
    (When a pointer in C is incremented, it points to the next object of whatever
    type it's a pointer to, so if you have a pointer to a CStruct, it will
    point to the following CStruct.)

    > 'if !(a = b)' means


    This is a syntax error. It needs ()s.

    > 1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
    > '=')
    > 2) a=b and if b=0 then....
    > 3) something else?


    if (!expr) {
    }

    executes the code if expr is equal to zero.

    a = b

    assigns b's value into a, then yields a's value.

    Thus,

    if (!(a = b)) {
    /* code */
    }

    assigns b's current value into a, and if the result is zero, executes code.

    > Third stupid question:


    > When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
    > couldn't find the 'dealloc' function in the prog.


    Very good question. "_fmalloc" is not a standard C function. On most
    implementations I've used, all program memory is freed automatically
    on exit, but this function may behave differently.

    > If someone knows where to find basic c++ help (*.hlp, *.doc,...) on the
    > net...


    No clue, I don't do C++.

    > Thanks a lot for your help, and please excuse the stupidity of my
    > questions.


    Stupidity is bearable, but I can tell you something you MUST do:

    Be. More. Careful.

    C is an extremely picky language. The punctuation MATTERS. You cannot
    just paraphrase or type from memory unless your memory is a LOT better
    than it apparently is now. If you are making the same kinds of errors
    in transcription and translation that you made in creating this post, you
    are not producing anything that will be of value to you or anyone else.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Aug 31, 2010
    #2
    1. Advertising

  3. Jean-Claude ROVIER

    Nobody Guest

    On Tue, 31 Aug 2010 21:20:13 +0000, Seebs wrote:

    >> Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
    >> any suggestions :) )

    >
    > djgpp or whatever they call it these days. Free. Pretty good.


    djgpp is gcc for DOS. MinGW is gcc for Windows.

    Microsoft offer a free version of Visual C++ ("Express" edition).
    Nobody, Sep 1, 2010
    #3
  4. Jean-Claude ROVIER

    Eric Sosman Guest

    On 8/31/2010 5:02 PM, Jean-Claude ROVIER wrote:
    >
    > Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
    > any suggestions :) ) and start learning C/C++, I need to translate a C
    > prog into TP.
    >
    > Here are the supid questions:
    >
    > 1st:
    >
    > I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
    > is.
    > If the program does 'MyPointer = p++' what does this mean?
    >
    > 1) MyPointer = p; increment p of 1;
    > 2) MyPointer = p; Increment p of SizeOf(CStruct);


    Yes to both. MyPointer (assuming it's a pointer of a suitable
    type) gets the old value of p, and p advances by one -- that is,
    to the next CStruct, whether a CStruct is one byte or forty-two bytes
    in size. Pointer arithmetic in C is done in units of the thing that
    is pointed at; it can never produce a pointer to the "middle" of such
    an object (unless you're doing evil type-punning).

    > 3) increment p of 1; MyPointer = p;
    > 4) increment p op SizeOf(CStruct); MyPointer = p;


    Your phraseology is strange to me and I may have misunderstood
    you, but no: The ++ *post*fix operator yields the original value of
    its operand, while the ++*pre*fix operator yields the new value. To
    avoid any confusion that "pointerness" may be causing:

    int x = 42;
    int y = x++; /* now y == 42, x == 43 */
    int z = ++x; /* now z == 44, x == 44 */

    > 5) something else?
    >
    > Second stupid question:
    >
    > 'if !(a = b)' means
    >
    > 1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
    > '=')


    No: Your observation that `=' is not `==' is correct. C's `='
    is like Pascal's `:=', and C's `==' is like Pascal's `='.

    > 2) a=b and if b=0 then....


    Yes. Or more exactly, "a=b and if a==0". The value of b may or
    may not be zero (consider b == 0.42 with an integer a); it's the value
    assigned to a that matters.

    > 3) something else?
    >
    > Third stupid question:
    >
    > When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
    > couldn't find the 'dealloc' function in the prog.


    This _fmalloc() function isn't part of C, but part of somebody's
    C-with-extras framework. Sorry; I don't know what its rules are.

    > Thanks a lot for your help, and please excuse the stupidity of my
    > questions.


    The stupidest question of all is the one you failed to ask when
    you should have.

    --
    Eric Sosman
    lid
    Eric Sosman, Sep 1, 2010
    #4
  5. Jean-Claude ROVIER

    Jorgen Grahn Guest

    On Tue, 2010-08-31, Seebs wrote:
    > On 2010-08-31, Jean-Claude ROVIER <> wrote:
    >> I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
    >> world.

    >
    > What's that?


    Turbo Pascal, I imagine. Last time I saw it Ronald Reagan was
    president of the US ...

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Sep 1, 2010
    #5
  6. Behind China Blue Eyes writes:
    >> Second stupid question:
    >>
    >> 'if !(a = b)' means

    >
    > a := b; if not (a<>0) then ...
    >
    >> 2) a=b and if b=0 then....


    Are you sure ??!! This looks crazy.

    >> Third stupid question:
    >>
    >> When I use a _fmalloc(size). Would that block be 'de-allocated' on
    >> exit? I couldn't find the 'dealloc' function in the prog.

    >
    > With the usual C libraries, the dispose procedure is named
    > free(pointer).


    If I do this I am getting a Segmention Fault...
    Jean-Claude ROVIER, Sep 1, 2010
    #6
  7. Jean-Claude ROVIER

    Ian Collins Guest

    On 09/ 2/10 10:04 AM, Jean-Claude ROVIER wrote:
    > Behind China Blue Eyes writes:
    >>> Second stupid question:
    >>>
    >>> 'if !(a = b)' means

    >>
    >> a := b; if not (a<>0) then ...
    >>
    >>> 2) a=b and if b=0 then....

    >
    > Are you sure ??!! This looks crazy.
    >
    >>> Third stupid question:
    >>>
    >>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
    >>> exit? I couldn't find the 'dealloc' function in the prog.

    >>
    >> With the usual C libraries, the dispose procedure is named
    >> free(pointer).

    >
    > If I do this I am getting a Segmention Fault...


    Then whatever you are trying to free wasn't allocated with one of the
    standard allocation functions.

    --
    Ian Collins
    Ian Collins, Sep 1, 2010
    #7
  8. Jean-Claude ROVIER <> writes:
    > Behind China Blue Eyes writes:
    >>> Second stupid question:
    >>>
    >>> 'if !(a = b)' means

    >>
    >> a := b; if not (a<>0) then ...
    >>
    >>> 2) a=b and if b=0 then....

    >
    > Are you sure ??!! This looks crazy.


    The original 'if !(a = b)' is a syntax error. If you'll post the actual
    line of code, we can explain it.

    >>> Third stupid question:
    >>>
    >>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
    >>> exit? I couldn't find the 'dealloc' function in the prog.

    >>
    >> With the usual C libraries, the dispose procedure is named
    >> free(pointer).

    >
    > If I do this I am getting a Segmention Fault...


    You need to read the documentation for _fmalloc(). It's non-standard.

    The standard allocation function in C is malloc(); malloc() calls should
    be matched with free() calls.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 1, 2010
    #8
  9. Jean-Claude ROVIER

    Moi Guest

    On Wed, 01 Sep 2010 22:04:02 +0000, Jean-Claude ROVIER wrote:

    > Behind China Blue Eyes writes:
    >>> Second stupid question:
    >>>
    >>> 'if !(a = b)' means

    >>
    >> a := b; if not (a<>0) then ...
    >>
    >>> 2) a=b and if b=0 then....

    >
    > Are you sure ??!! This looks crazy.
    >
    >>> Third stupid question:
    >>>
    >>> When I use a _fmalloc(size). Would that block be 'de-allocated' on
    >>> exit? I couldn't find the 'dealloc' function in the prog.

    >>
    >> With the usual C libraries, the dispose procedure is named
    >> free(pointer).

    >
    > If I do this I am getting a Segmention Fault...


    There is an error on line 42.

    AvK
    Moi, Sep 1, 2010
    #9
  10. Jean-Claude ROVIER

    Seebs Guest

    On 2010-09-01, Jean-Claude ROVIER <> wrote:
    > Behind China Blue Eyes writes:
    >>> Second stupid question:
    >>> 'if !(a = b)' means


    >> a := b; if not (a<>0) then ...


    >>> 2) a=b and if b=0 then....


    > Are you sure ??!! This looks crazy.


    If you don't want to listen to the answers people give, why did you
    ask?

    One of the big differences between C and Pascal is that C is a lot more
    prone to "side-effects" -- expressions which change things along with
    evaluating to values.

    >> With the usual C libraries, the dispose procedure is named
    >> free(pointer).


    > If I do this I am getting a Segmention Fault...


    This is too unspecific for us to do much but point out that "_fmalloc"
    is not part of the *usual* C libraries, so you'll need to make your own
    guesses or read some documentation.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Sep 2, 2010
    #10
  11. Seebs <> writes:
    > On 2010-09-01, Jean-Claude ROVIER <> wrote:
    >> Behind China Blue Eyes writes:
    >>>> Second stupid question:
    >>>> 'if !(a = b)' means

    >
    >>> a := b; if not (a<>0) then ...

    >
    >>>> 2) a=b and if b=0 then....

    >
    >> Are you sure ??!! This looks crazy.

    >
    > If you don't want to listen to the answers people give, why did you
    > ask?


    Actually, "not (a<>0)" is a bit crazy; the C equivalent would be
    "!(a!=0)".

    [...]

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Sep 2, 2010
    #11
  12. On 1 Sep, 23:04, Jean-Claude ROVIER <> wrote:
    > Behind China Blue Eyes writes:


    <snip>

    > >> When I use a _fmalloc(size). Would that block be 'de-allocated' on
    > >> exit? I couldn't find the 'dealloc' function in the prog.

    >
    > > With the usual C libraries, the dispose procedure is named
    > > free(pointer).

    >
    > If I do this I am getting a Segmention Fault...


    do what? Post your code.

    Slow down. Think more.
    Nick Keighley, Sep 2, 2010
    #12
  13. Jean-Claude ROVIER

    Default User Guest

    "Behind China Blue Eyes" <> wrote in message
    news:-september.org...
    > In article <i5miki$fiu$>,
    > Jean-Claude ROVIER <> wrote:


    >> >> When I use a _fmalloc(size). Would that block be 'de-allocated' on
    >> >> exit? I couldn't find the 'dealloc' function in the prog.
    >> >
    >> > With the usual C libraries, the dispose procedure is named
    >> > free(pointer).

    >>
    >> If I do this I am getting a Segmention Fault...

    >
    > I don't know what fmalloc is. Perhaps its free function is ffree?


    If it's the version referenced below, then it would be _ffree().

    http://support.microsoft.com/kb/12159





    Brian
    --
    Day 575 of the "no grouchy usenet posts" project.
    Default User, Sep 2, 2010
    #13
  14. Jean-Claude ROVIER

    iC and iC++ Guest

    On Aug 31, 5:02 pm, Jean-Claude ROVIER <> wrote:
    >   Hi All,
    >
    > I'm really sorry for the dumbness of my questions but I'm from the TP/Pas
    > world.
    > Before I get enough money to buy to good C/C++ compiler (for DOS/Win/NT,
    > any suggestions :) ) and start learning C/C++, I need to translate a C
    > prog into TP.
    >
    > Here are the supid questions:
    >
    > 1st:
    >
    > I've got p as a pointer on a CStruct. p = *CStruct. No matter was CStruct
    > is.
    > If the program does 'MyPointer = p++' what does this mean?
    >
    > 1) MyPointer = p;                  increment p of 1;
    > 2) MyPointer = p;                  Increment p of SizeOf(CStruct);
    > 3) increment p of 1;               MyPointer = p;
    > 4) increment p op SizeOf(CStruct); MyPointer = p;
    > 5) something else?
    >
    > Second stupid question:
    >
    > 'if !(a = b)' means
    >
    > 1) if not a equal b (Hmmm I really don't believe this: equal is '==' not
    > '=')
    > 2) a=b and if b=0 then....
    > 3) something else?
    >
    > Third stupid question:
    >
    > When I use a _fmalloc(size). Would that block be 'de-allocated' on exit? I
    > couldn't find the 'dealloc' function in the prog.
    >
    > If someone knows where to find basic c++ help (*.hlp, *.doc,...) on the
    > net...
    >
    > Thanks a lot for your help, and please excuse the stupidity of my
    > questions.


    I suggest you purchase an excellent book called The Complete
    Reference, 4th Ed. [Paperback] by Helbert schildt

    http://www.amazon.com/C-Complete-Re...=sr_1_8?s=books&ie=UTF8&qid=1283460406&sr=1-8

    Before I got this book, I had to deal with a lot of asswipes in this
    forum. After I got a hold of this book, it has become my first and
    most of the time, last place of reference.
    iC and iC++, Sep 2, 2010
    #14
  15. Jean-Claude ROVIER

    Seebs Guest

    On 2010-09-02, Vincenzo Mercuri <> wrote:
    > iC and iC++ wrote:
    >> I suggest you purchase an excellent book called The Complete
    >> Reference, 4th Ed. [Paperback] by Helbert schildt


    What a fascinating (set of) misspelling(s).

    >> Before I got this book, I had to deal with a lot of asswipes in this
    >> forum. After I got a hold of this book, it has become my first and
    >> most of the time, last place of reference.


    What the poster does not mention is whether any of his code compiles,
    let alone runs.

    > http://www.seebs.net/c/c_tcn4e.html


    That was a FUN afternoon's work.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Sep 2, 2010
    #15
  16. Jean-Claude ROVIER

    Seebs Guest

    On 2010-09-02, iC and iC++ <> wrote:
    > I suggest you purchase an excellent book called The Complete
    > Reference, 4th Ed. [Paperback] by Helbert schildt


    To the OP: iC is messing with you here. The book is spectacularly
    bad, riddled with errors, and one of the worst sources you could pick
    for learning about C. Recommending this to new posters is some sort
    of hazing thing, like sending people for a "left-handed monkey wrench"
    or whatever the pranks are these days.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Sep 2, 2010
    #16
  17. On 2 Sep, 22:53, Seebs <> wrote:
    > On 2010-09-02, iC and iC++ <> wrote:
    >
    > > I suggest you purchase an excellent book called The Complete
    > > Reference, 4th Ed. [Paperback] by Helbert schildt

    >
    > To the OP:  iC is messing with you here.  The book is spectacularly
    > bad, riddled with errors, and one of the worst sources you could pick
    > for learning about C.  Recommending this to new posters is some sort
    > of hazing thing, like sending people for a "left-handed monkey wrench"
    > or whatever the pranks are these days.


    go to stores and ask them to give you a "long weight"
    Nick Keighley, Sep 3, 2010
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam White
    Replies:
    10
    Views:
    1,895
    Joerg Jooss
    Nov 3, 2004
  2. Marcin Misiewicz
    Replies:
    1
    Views:
    1,923
    zoopy
    Aug 19, 2004
  3. Brandon McCombs
    Replies:
    4
    Views:
    499
    Richard Wheeldon
    Aug 28, 2006
  4. rincewind

    stupid, STUPID question!

    rincewind, Apr 19, 2009, in forum: HTML
    Replies:
    25
    Views:
    1,008
  5. jean francois

    Three stupid C questions: ++,...

    jean francois, Jun 11, 2012, in forum: C Programming
    Replies:
    23
    Views:
    801
Loading...

Share This Page