dereferencing problem

Discussion in 'C Programming' started by Bill Cunningham, Apr 12, 2014.

  1. If the OP is lucky, it segfaults.

    If not, it stores it some place in memory where something else is
    supposed to be, causing strange effects sometime later.

    Not noticing the missing #include before, this is what I wrote
    about previously.

    -- glen
     
    glen herrmannsfeldt, Apr 13, 2014
    #21
    1. Advertisements

  2. Bill Cunningham

    Ian Collins Guest

    The OP isn't lucky, he's a troll!
     
    Ian Collins, Apr 13, 2014
    #22
    1. Advertisements

  3. [snip]

    Ok so how exactly am I going to correct this? Using memset or malloc ? Or
    using that ampersand? I understand what's wrong, but I need to know how to
    correct it.


    Bill
     
    Bill Cunningham, Apr 13, 2014
    #23
  4. Bill Cunningham

    Ian Collins Guest

    Look back at some of your near identical posts and re-read the answers.
     
    Ian Collins, Apr 13, 2014
    #24
  5. What on earth makes you think that memset is a suitable substitute for
    free? Or that the two are even related?

    Your second example causes a memory leak if the structure is
    dynamically allocated instead of defined. It also causes undefined
    behavior whenever the size of the structure is greater than the size
    of the pointer.
     
    Barry Schwarz, Apr 13, 2014
    #25
  6. Yes smarter ass, I'm definitely not as good as some of the others
    here. That's why when I ask for help I try not to make assumptions
    about the problem.

    These messages tell us that your original assertion that the error
    occurred on line 7 was wrong. They also tell us that your assertion
    that you only had one dereference was also wrong.

    Several people responded telling you that pa had never been assigned a
    value. They were correct but these error messages tell us that the
    compiler did not detect this error. It was complaining about the fact
    that while addrinfo was indeed known to be a struct type you had never
    provided a complete definition for that type. So by taking the lazy
    way out, you led people down the wrong path.
     
    Barry Schwarz, Apr 13, 2014
    #26
  7. Are you saying you cannot understand the documentation for the
    compiler system you use? Your final comment suggests you don't
    consider it worthwhile even to try.
     
    Barry Schwarz, Apr 13, 2014
    #27
  8. Even you cannot believe that memset is a suitable replacement for
    malloc or the reverse.
     
    Barry Schwarz, Apr 13, 2014
    #28
  9. malloc is good. memset was shown in the code so I assume they know best.
    You know I certainly don't. So well...malloc is good.
     
    Bill Cunningham, Apr 13, 2014
    #29
  10. No. Not the last time I looked anyway. And that's been awhile.

    Your final comment suggests you don't
    I post all my source code in one column.
     
    Bill Cunningham, Apr 13, 2014
    #30
  11. No I didn't. They were right. They were smarter than the compiler. Don't try
    to make me look like I'm trying to deceive people. I was having some
    problems with C In practical use with BSD sockets.

    Bill
     
    Bill Cunningham, Apr 13, 2014
    #31
  12. The only C statement that can fit in one column is the null statement
    consisting of a single semicolon. While I recall you coding null
    statements in the past, it was usually be accident and incorrect.
    However you did not code any in this thread so this is just one more
    assertion that is obviously false.
     
    Barry Schwarz, Apr 13, 2014
    #32
  13. They were correct in identifying an error in your code but it was not
    the error you were asking about. Even after you assign a value to
    pointer pa, the compiler would still generate the same diagnostics
    since the structure is still incomplete.

    I never said you were deliberately trying to deceive people. I said
    that by providing incomplete information they were forced to make what
    turned out to be false assumptions. Only you know if providing the
    incomplete data was a deliberate ploy on your part or not.
     
    Barry Schwarz, Apr 13, 2014
    #33
  14. Nowhere in the code you posted was memset used. I have no idea why
    you introduced it in two different messages as a possible substitute
    for either free or malloc
     
    Barry Schwarz, Apr 13, 2014
    #34
  15. It does help a lot to give the actual messages early.

    Posting no code, or hundreds of lines for us to search through,
    could be considered lazy.

    Compilers should be able to detect that a pointer was never
    assigned a value before being used, but many don't. The sample
    was small enough that it was pretty easy to see.


    -- glen
     
    glen herrmannsfeldt, Apr 13, 2014
    #35
  16. Bill Cunningham

    Osmium Guest

    Introducing a more or less random word from "the biz" is one of Bill's
    trademarks.
    Perhaps you are seeing the handiwork of a Beautiful Mind? Only a guy who
    can tell what Napoleon ate at his last meal by analyzing a single Napoleon
    head hair could figure Bill out.
     
    Osmium, Apr 14, 2014
    #36
  17. Bill Cunningham

    Les Cargill Guest

    Or declare it static. We're in main ( not that it really
    matters ) .
    I think so too.
     
    Les Cargill, Apr 14, 2014
    #37
  18. (snip, I wrote)
    Well, they could be different. auto should be allocated on the
    stack, though it will stay there the whole time (until main
    returns).

    Also, some systems have unusual restrictions on static storage.
    Some years ago in an Alpha/OSF1 system with 16GB RAM, I tried
    to allocate and initialize a 100k byte static array.

    That was too big.

    I think I just made it smaller, but maybe auto instead.

    -- glen
     
    glen herrmannsfeldt, Apr 14, 2014
    #38
  19. Bill Cunningham

    Les Cargill Guest

    How bizarre. 64kbyte limitation? I thought the Alpha was a 64 bit
    machine - at least true 32 bit.

    You'd think toolchains would *encourage* static allocation since it's
    the most conservative way.
     
    Les Cargill, Apr 14, 2014
    #39
  20. http://linux.die.net/man/3/getaddrinfo

    Not seeing this or not knowing about it now is lazy.
     
    Bill Cunningham, Apr 14, 2014
    #40
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.