Thread: any way to determine size of array thats a function parameter?

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by Kleid-0
    rofl, yeah this is pretty deep. But I do believe everyone is correct in this debate, it's just the way they look at it that sparks the disbelieve in the opposition.
    Well, actually...

    sizeof(x)/sizeof(y) is a constant expression, so most likely, the compiler will evaluate it. Thus, the machine/hardware/cpu/whatever has little to do with it (it will do the calculation for the compiler, but the compiler will decide how the computation is done).

    If it wasn't a constant expression, it would still be an integer division, performed by the integer unit of the CPU, and would thus yield 0 (in our particular case), not 0.5.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    At the risk of being banned or suspended: I am sillyI am sillyI am sillyI am silly! I said merely I am sillyI am sillyI am sillyI am sillying said i I am sillyI am sillyI am sillyI am sillying divided 4/8 in my god damn head, you dick! You are furthermore making yourself look overly arrogant and incompetent by arguing an entirely tangent topic.

    [edit]
    That was directed at Thantos not you Corned Bee.
    [/edit]

  3. #33
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Thanks mod for being kind and thank you content filters for not soiling my name too much. Am I getting a little angry? Understatement.
    Last edited by master5001; 12-18-2004 at 11:17 PM.

  4. #34
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    One last thought before I pretty much stop posting here, at what point did I say anything suggestive of the function returning .5? Oh thats right never. Good luck to all of you as far as communicating with other humans goes. Its gonna be an uphill battle for most of you.

  5. #35
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by master5001
    > Which on my machine would be .5
    RIGHT! I did not say on my compiler. On my 32-bit x86 architecture cpu, a double is 8 bytes in size and a point to a double is 4 bytes in size. Lets see 4/8 = .5. This particular issue is a good example to people who don't understand why integer math truncates decimals. Indeed it would be the best, as you cannot have a partial byte.
    Are you just completely stupid? Is 4 an integer? Is 8 an integer? If you divide one integer by another, do you EVER get a floating point result without specificly casting it? NO YOU DON'T! EVER. ONE MORE TIME: EVER!

    You see that? EVER! NOT EVER! Your "machine" will NOT EVER take two integers to apply division to and force them to be floating point numbers JUST FOR THE HELL OF IT, so it can convert it back to an integer. NOT EVER. GOT THAT? NOT EVER.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #36
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    But quzah master5001 is not talking about the compiler, I believe. So it doesn't matter if they're integers or not, he's talking about the processor itself and how it comes up with 0.5, and THEN the compiler makes it 0 because it has to be an integer..? I've been trying to follow along here, so let's proceed! Wait nevermind I reread CornedBee's post.

    "performed by the integer unit of the CPU" --CornedBee

    It seems we have a winner here.
    Last edited by Kleid-0; 12-19-2004 at 03:27 AM.

  7. #37
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Kleid-0 when you have two integers being divided the processor gets the normal div command. This is the "default" type of divison. It will only result in an integer answer.

    When you have floating point numbers the processor gets a different instructions that tell it to do floating point division.

    So at no point in time does 4/8 = .5 in the processor.

    Edit: Beaten by the edit
    Last edited by Thantos; 12-19-2004 at 03:30 AM.

  8. #38
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by CornedBee
    What an utterly pointless debate...
    that about sums it up... no points... it's an integer division...

    let's look at it another way: say two parents get divorced and have one kid. you can't cut the kid in half and give one half to one parent and the other half to the other parent... that would get quite messy, agree? so in this case, 1 kid per 2 parents cannot equal .5 kids per parent.

    however, if you're talking about a total estate of $1.00, that is something that can be split - now each parent can take home $0.50 and be happy... maybe... as long as they clean the bloody mess that was their kid off the sidewalk.

    point is: some things can be split, some can't. integers can't. even if in your mind every divorce is a kid physically chainsawed in half (vertically, of course, for fairness' sake), it's not going to happen, and the flaw is in your thinking.

    point is (again): don't tell a parent their child will be cut in half when they get divorced if it isn't going to happen.


    I am sillyI am sillyI am sillyI am silly
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #39
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by Kleid-0
    But quzah master5001 is not talking about the compiler, I believe. So it doesn't matter if they're integers or not, he's talking about the processor itself and how it comes up with 0.5, and THEN the compiler makes it 0 because it has to be an integer..? I've been trying to follow along here, so let's proceed! Wait nevermind I reread CornedBee's post.

    "performed by the integer unit of the CPU" --CornedBee

    It seems we have a winner here.
    I nor did I at any point say my cpu would perform this calculation. I said that the when dividing the size of a pointer to a double (which on my machine--for prelude's sake NOT my compiler--is 4 bytes) by the size of a double (8 bytes on my machine) is *drum role* 0.5. I will repeat myself one last time since some of you have selective reading patterns.

    The following code:

    Example:
    Code:
    size_t TheOnePartWeAllSeemToAgreeOn(double *array) {
      return sizeof(array)/sizeof(double);
    }
    
    int main(void) {
      double array[0x100];
    
      printf("The one undisputable part of this whole ****ing debate: %d",
        TheOnePartWeAllSeemToAgreeOn(array));
    
      return 0;
    }
    Will print the following:
    Code:
    The one undisputable part of this whole ****ing debate: 0
    Why? Because integer math truncates decimals. Where are you all getting lost? I HAVE NO IDEA! Apparently other than using a calculator that only does integer math many of you clearly seem to lack the ability to perform simple division in your heads. It amazes me how oblivious you guys are. Profound. I'm not going to post on this anymore because its become pointless.

    Between some of you basically ignoring details that have been said (which is frustrating) and one of you not knowing the difference between a computer, a compiler and mental math (amusing), this has become like watching the Three Stooges put together a car.

    [edit]
    >result in an integer answer.

    >When you have floating point numbers the processor gets a >different instructions that tell it to do floating point division.

    >So at no point in time does 4/8 = .5 in the processor.

    Interesting, so your brain is only capable of dividing through the div command? I appologize for flaming you earlier Thantos, it turns out you aren't a slightly clueless human afterall. Instead you are a highly advanced android.
    [/edit]
    Last edited by master5001; 12-19-2004 at 06:52 AM.

  10. #40
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I nor did I at any point say my cpu would perform this calculation. I said that the when dividing the size of a pointer to a double (which on my machine--for prelude's sake NOT my compiler--is 4 bytes) by the size of a double (8 bytes on my machine) is *drum role* 0.5. I will repeat myself one last time since some of you have selective reading patterns.
    Just get a god damn clue, alright? Let's go over your argument:

    1) Your "machine" says the result of dividing two integers will give a floating point number.
    Quote Originally Posted by master5001
    Is wrong as you are saying the size of a pointer divided by the size of a double. Which on my machine would be .5, which I guarantee you is not what you were looking for
    2) Apparently, you really meant your "machine", and not a compiler:
    Quote Originally Posted by master5001
    RIGHT! I did not say on my compiler. On my 32-bit x86 architecture cpu, a double is 8 bytes in size and a point to a double is 4 bytes in size. Lets see 4/8 = .5. This particular issue is a good example to people who don't understand why integer math truncates decimals.
    3) You really really want us to know you're not talking about your compiler, but your "machine":
    Quote Originally Posted by master5001
    There is a distinction between my compiler and hardware. I never refer to my compiler as my hardware. I truthfully don't see how what I said is different from what I mean. And ultimately I don't really care at this point. I'm going to just shut off my compiler (since you guys want me to call my machine my compiler now) and from now on state both what I mean and what I don't mean since it may be the only way to make my comments crystal clear.
    So now you have quantified your "machine" as a 32-bit x86 based CPU. BUT WAIT, it gets better!

    4) You say your "machine", not your CPU does the calculation:
    Quote Originally Posted by master5001
    nor did I at any point say my cpu would perform this calculation.
    Ok, so where in your magical "machine" is this calculation being preformed? It's apparently not your compiler. It's apparently not your CPU. So, please, oh all knowing, tell us, where is this magical integer math, which results yields a floating point number, is this calculation taking place?

    The FACT remains, it is IMPOSSIBLE for your "machine", your "compiler", your "CPU", your whatever you feel like calling it today, to yield a floating point value from two integers being divided. IT DOES NOT HAPPEN. EVER. Oh, sure, maybe in your MIND it does. But you said your "machine" is a "32-bit x86 architecture", which some how, doesn't process integers in its CPU.

    Oh, right, your "machine" apparently generates floating point numbers as a result of integer division. Oh, that's right it somehow gives you a .5 as a result, but it doesn't "evaluate to" it.

    Give me a break. Do you even read what you write?

    Quzah.
    Last edited by quzah; 12-19-2004 at 07:29 AM.
    Hope is the first step on the road to disappointment.

  11. #41
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok I read some of my negative feed back on this one. Look here is the thing, Prelude, Thantos, Quzah, I'm not wrong. Nor am I copping out of admittion to being wrong. I think if I had said that the function itself evaluated to zero to begin with you guys would have never started getting picky. That said, we have all said words out of anger, me especially. You guys are my peers and I appologize for treating you like crap. I'm really not wrong as much as I think I could have perhaps been more thorough as to what I meant in my original statement.

    That said, I'm sorry both publicly, and privately being an I am sillyI am sillyI am sillyI am sillyI am sillyI am sillyI am silly to you guys. Friday/Saturday were kind of stressful and I guess I was in a ........y mood to begin with. I'm not going to concede the point since truthfully I fail to see evidence disproving me, but I do see evidence pointing to the fact i was indeed not clear enough in what i meant to begin with. I can understand if you three no longer think my opinion has any value, I just don't want you guys to think I'm being a dick for no reason.

    [edit]
    Quzah, just to make what i was saying crystal clear by "on my machine" I was refering to the size of my data types. Again, poor wording on my behalf.

    As you well know a double can be larger to 8 bytes in size, as can a pointer. But in fairness to you, I didn't say that, I said on my machine which is somewhat implicit of the fact that I mean how my cpu will handle:

    Code:
    mov edx, 0
    mov eax, 4
    mov esi, 8
    div esi
    What I was saying is:
    sizeof(double) = 8 on master5001's computer
    sizeof(double *) = 4 on master5001's computer.

    Again, ........y mood. Using poor wording and flaming you guys for jumping on my wording that though you probably understood what I meant, anyone who may not have understood may have become mislead.
    [/edit]
    Last edited by master5001; 12-19-2004 at 07:39 AM.

  12. #42
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm not wrong.
    I know how you feel, I hate being wrong myself. But I'm not going to continue this thread because it's gone too far. Any clarification I need can be gotten through PM.

    >You guys are my peers and I appologize for treating you like crap.
    I accept your appology (though I can't for everyone else), but I'm afraid it's already too late. I had a great amount of respect for you and your posts were among those that I would gloss over in my error checking addiction because you're usually very accurate. So let me say it right now, I don't care if you're right or wrong. I think you're wrong, you think you're right, and I've been in countless debates of this type. What I do care about is that you've reacted so strongly and negatively to people who were initially very polite in helping you to make your post better.

    Everyone makes mistakes and bad decisions, but you've been destroying your reputation (and I don't mean those stupid little green bars) just to salvage your pride. What I care about is that you think so little of us and that you're willing to propagate a flame war over something so ridiculously trivial as this. That hurts me, and I was very close to placing you on my ignore list because you were pushing me to the limits of my patience.

    You've lost a lot of respect in my eyes, and not because of poor wording or failure to admit a mistake. It has more to do with how you treat those who are trying to help you. I expect that from beginners who think they know everything and have a bad attitude to begin with. A well respected senior member with plenty of experience should know better.

    Now, for any mod passing by, I want this thread to be closed. It reached the end of its usefulness a long time ago.
    My best code is written with the delete key.

  13. #43
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Right or wrong, some of my actions were rather immature. And if I lost any respect from anyone it was my own undoing and right or wrong, the perception of me at the end of anything is determined exclusively by my own actions. So any bad that I get from this point on is no one's fault but my own. Closing sounds good because its obvious this is at the same place it was 30+ posts ago.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing multidimensional/dynamic array to function
    By epyfathom in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 05:39 PM
  2. Fixing my program
    By Mcwaffle in forum C Programming
    Replies: 5
    Last Post: 11-05-2008, 03:55 AM
  3. dynamically defined array size in a function
    By earth_angel in forum C Programming
    Replies: 21
    Last Post: 05-28-2005, 01:44 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM