Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #27276 > unrolled thread

callback function

Started by"Bill Cunningham" <billcun@suddenlink.net>
First post2012-10-17 17:16 -0400
Last post2012-11-26 23:03 -0800
Articles 20 on this page of 72 — 17 participants

Back to article view | Back to comp.lang.c


Contents

  callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-17 17:16 -0400
    Re: callback function John Gordon <gordon@panix.com> - 2012-10-17 21:36 +0000
      Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-17 17:44 -0400
        Re: callback function John Gordon <gordon@panix.com> - 2012-10-17 21:51 +0000
          Re: callback function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-18 00:11 +0100
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:37 -0400
            Re: callback function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-19 01:16 +0100
            Re: callback function Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-20 06:48 -0700
      Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-18 10:45 +1300
        Re: callback function pete <pfiland@mindspring.com> - 2012-10-19 14:49 -0400
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 16:59 -0400
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 17:04 -0400
            Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-19 14:14 -0700
              Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 17:31 -0400
                Re: callback function Keith Thompson <kst-u@mib.org> - 2012-10-19 14:54 -0700
                  Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 18:42 -0400
      Re: callback function James Kuyper <jameskuyper@verizon.net> - 2012-10-17 17:47 -0400
      Re: callback function tom st denis <tom@iahu.ca> - 2012-10-19 04:44 -0700
        Re: callback function James Kuyper <jameskuyper@verizon.net> - 2012-10-19 08:24 -0400
    Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-17 14:39 -0700
      Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-17 17:50 -0400
        Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-18 11:00 +1300
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:20 -0400
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:24 -0400
            Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-18 22:30 -0700
            Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-20 11:58 +1300
              Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 19:27 -0400
                Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 19:43 -0400
                  Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-19 21:09 -0700
            Re: callback function Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-10-20 06:53 -0700
        Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-17 19:25 -0400
          Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-18 13:34 +1300
            Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-17 20:41 -0400
              Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-18 14:37 +1300
                Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:17 -0400
                  Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-20 11:54 +1300
                Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:54 -0400
                  Re: callback function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-19 01:23 +0100
                    Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 20:32 -0400
                      Re: callback function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-19 02:43 +0100
                        Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 16:56 -0400
                          Re: callback function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-19 22:10 +0100
                      Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-18 22:30 -0700
                        Re: callback function Kenneth Brody <kenbrody@spamcop.net> - 2012-10-19 12:37 -0400
                          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 16:52 -0400
      Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-19 18:44 -0400
        Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-19 21:09 -0700
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-20 15:01 -0400
            Re: callback function Keith Thompson <kst-u@mib.org> - 2012-10-20 12:47 -0700
            Re: callback function Les Cargill <lcargill99@comcast.com> - 2012-10-20 14:51 -0500
            Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-20 14:39 -0700
              Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-20 19:06 -0400
                Re: callback function Barry Schwarz <schwarzb@dqel.com> - 2012-10-20 22:22 -0700
                  Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-21 14:35 -0400
                  Re: callback function Kenneth Brody <kenbrody@spamcop.net> - 2012-10-22 10:58 -0400
                Re: callback function Bill Cunningham <billcun@suddenlink.net> - 2012-10-24 17:28 -0700
            Re: callback function Ian Collins <ian-news@hotmail.com> - 2012-10-21 11:32 +1300
              Re: callback function Keith Thompson <kst-u@mib.org> - 2012-10-20 15:51 -0700
        Re: callback function Robert Miles <milesrf@Usenet-News.net> - 2012-11-25 22:39 -0600
    Re: callback function Keith Thompson <kst-u@mib.org> - 2012-10-17 17:51 -0700
      Re: callback function Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-18 20:34 +0300
      Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:15 -0400
        Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:27 -0400
        Re: callback function Keith Thompson <kst-u@mib.org> - 2012-10-18 15:47 -0700
          Re: callback function "Bill Cunningham" <billcun@suddenlink.net> - 2012-10-18 18:52 -0400
        Re: callback function blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2012-10-25 10:01 +0000
          Re: callback function Kenneth Brody <kenbrody@spamcop.net> - 2012-10-25 12:44 -0400
            Re: callback function blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2012-10-26 12:48 +0000
    Re: callback function Robert Miles <milesrf@Usenet-News.net> - 2012-11-25 22:13 -0600
      Re: callback function Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-11-26 03:42 -0800
      Re: callback function James Kuyper <jameskuyper@verizon.net> - 2012-11-26 06:59 -0500
      Re: callback function Keith Thompson <kst-u@mib.org> - 2012-11-26 23:03 -0800

Page 1 of 4  [1] 2 3 4  Next page →


#27276 — callback function

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-17 17:16 -0400
Subjectcallback function
Message-ID<k5n77p$e5v$1@speranza.aioe.org>
    I have these 3 functions and before I compile I am going to ask about 
them. This is for qsort. I tried to tackle this once and couldn't get it I 
think I get it now. I don't like const's. They are a nuisance. You can't 
directly pass string literals to them you want to change. Maybe that's just 
the way C is though.

#include <stdio.h>
#include <stdlib.h>

int comp(constvoid *a,const void *b)
{
     int *ia=(constint *)a;
     int *ib=(const int *)b;
     return *ia-*ib;
}

void print_int_array(int *array,size_t len)
{
    size_t i;
    for (i=0;i<len;i++)
    printf("%d | ",array[i]);
    putchar('\n');
}

void sort_int(void)
{
    int num={1,3,6,4,5};
    size_t num_len=sizeof num/sizeof (int);
}

1 because of qsorts comp callback function parameters include a const do I 
need them and can I remove them as I have in the callback?
2. second line of sort_int. num is not a built in type so it doesn't require 
parenthesis does it?

Bill

[toc] | [next] | [standalone]


#27277

FromJohn Gordon <gordon@panix.com>
Date2012-10-17 21:36 +0000
Message-ID<k5n8dn$6m3$1@reader1.panix.com>
In reply to#27276
In <k5n77p$e5v$1@speranza.aioe.org> "Bill Cunningham" <billcun@suddenlink.net> writes:

> I don't like const's. They are a nuisance. You can't directly pass string
> literals to them you want to change.

Why are you passing something as const when you want to change it?  That's
kind of the opposite of const.

> void sort_int(void)
> {
>     int num={1,3,6,4,5};
>     size_t num_len=sizeof num/sizeof (int);
> }

> 2. second line of sort_int. num is not a built in type so it doesn't require 
> parenthesis does it?

Sizeof is a keyword, not a function call. It never needs parentheses.

Also, you forgot to declare num as an array.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#27279

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-17 17:44 -0400
Message-ID<k5n8sj$hph$1@speranza.aioe.org>
In reply to#27277
John Gordon wrote:

> Why are you passing something as const when you want to change it?
> That's
> kind of the opposite of const.
>
>> void sort_int(void)
>> {
>>     int num={1,3,6,4,5};
>>     size_t num_len=sizeof num/sizeof (int);
>> }
>
>> 2. second line of sort_int. num is not a built in type so it doesn't
>> require parenthesis does it?
>
> Sizeof is a keyword, not a function call. It never needs parentheses.

    try sizeof int and see if that works. If not trry sizeof (int). It 
doesn't work on my machine.

> Also, you forgot to declare num as an array.

oops. I see that.

[toc] | [prev] | [next] | [standalone]


#27284

FromJohn Gordon <gordon@panix.com>
Date2012-10-17 21:51 +0000
Message-ID<k5n98r$a3f$1@reader1.panix.com>
In reply to#27279
In <k5n8sj$hph$1@speranza.aioe.org> "Bill Cunningham" <billcun@suddenlink.net> writes:

> > Sizeof is a keyword, not a function call. It never needs parentheses.

>     try sizeof int and see if that works. If not trry sizeof (int). It 
> doesn't work on my machine.

Whoops, I was mistaken.  If you're getting the size of a variable you
don't need parentheses.  But if you're getting the size of a type, you do
need them.

(And it's an operator, not a keyword.  Wrong all around!)

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#27289

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-18 00:11 +0100
Message-ID<0.a4cce7c7216e0bfa98ee.20121018001108BST.87lif44rub.fsf@bsb.me.uk>
In reply to#27284
John Gordon <gordon@panix.com> writes:

> In <k5n8sj$hph$1@speranza.aioe.org> "Bill Cunningham" <billcun@suddenlink.net> writes:
>
>> > Sizeof is a keyword, not a function call. It never needs parentheses.
>
>>     try sizeof int and see if that works. If not trry sizeof (int). It 
>> doesn't work on my machine.
>
> Whoops, I was mistaken.  If you're getting the size of a variable you
> don't need parentheses.  But if you're getting the size of a type, you do
> need them.
>
> (And it's an operator, not a keyword.  Wrong all around!)

No, it's not as bad as that.  It *is* a keyword.  It's an operator, too,
but that does not stop it being a keyword.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#27322

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-18 18:37 -0400
Message-ID<k5q0aq$vsd$1@speranza.aioe.org>
In reply to#27284
John Gordon wrote:

> Whoops, I was mistaken.  If you're getting the size of a variable you
> don't need parentheses.  But if you're getting the size of a type,
> you do
> need them.
>
> (And it's an operator, not a keyword.  Wrong all around!)

    That's fine John I appreciate your opinion though yes you where wrong. 
No problem. But be forewarned, this *could* be the start that leads you to 
the *outgroup* If you start asking questions especially you should know as a 
computer programming expert (ingroup) and sticking yourself out there...Be 
careful.

Bill

[toc] | [prev] | [next] | [standalone]


#27327

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-19 01:16 +0100
Message-ID<0.f0557fbf0ecccce4f5a4.20121019011644BST.87a9vj48pf.fsf@bsb.me.uk>
In reply to#27322
"Bill Cunningham" <billcun@suddenlink.net> writes:

> John Gordon wrote:
>
>> Whoops, I was mistaken.  If you're getting the size of a variable you
>> don't need parentheses.  But if you're getting the size of a type,
>> you do
>> need them.
>>
>> (And it's an operator, not a keyword.  Wrong all around!)
>
>     That's fine John I appreciate your opinion though yes you where
>     wrong. 

Actually he's not "wrong all around" -- sizeof *is* a keyword.  It's an
operator, too, but it's also a keyword.

<snip sociology>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#27415

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2012-10-20 06:48 -0700
Message-ID<0b0b147d-4038-46f4-88ce-e6c7b3062f27@s14g2000vba.googlegroups.com>
In reply to#27322
On Oct 18, 11:37 pm, "Bill Cunningham" <bill...@suddenlink.net> wrote:
> John Gordon wrote:
> > Whoops, I was mistaken.  If you're getting the size of a variable you
> > don't need parentheses.  But if you're getting the size of a type,
> > you do
> > need them.
>
> > (And it's an operator, not a keyword.  Wrong all around!)
>
>     That's fine John I appreciate your opinion though yes you where wrong.
> No problem. But be forewarned, this *could* be the start that leads you to
> the *outgroup* If you start asking questions especially you should know as a
> computer programming expert (ingroup) and sticking yourself out there...Be
> careful.

If you're going to talk crap could you confine yourself to the C
language, as you usually do?

[toc] | [prev] | [next] | [standalone]


#27280

FromIan Collins <ian-news@hotmail.com>
Date2012-10-18 10:45 +1300
Message-ID<ae8n78Fo8jlU5@mid.individual.net>
In reply to#27277
On 10/18/12 10:36, John Gordon wrote:
> In<k5n77p$e5v$1@speranza.aioe.org>  "Bill Cunningham"<billcun@suddenlink.net>  writes:
>
>> void sort_int(void)
>> {
>>      int num={1,3,6,4,5};
>>      size_t num_len=sizeof num/sizeof (int);
>> }
>
>> 2. second line of sort_int. num is not a built in type so it doesn't require
>> parenthesis does it?
>
> Sizeof is a keyword, not a function call. It never needs parentheses.

Except, as in this case, where its argument is a type.

See what happens when you get sucked into a Bill troll?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#27371

Frompete <pfiland@mindspring.com>
Date2012-10-19 14:49 -0400
Message-ID<5081A0A6.4463@mindspring.com>
In reply to#27280
Ian Collins wrote:
> 
> On 10/18/12 10:36, John Gordon wrote:

> > Sizeof is a keyword, not a function call.
> > It never needs parentheses.
> 
> Except, as in this case, where its argument is a type.
> 
> See what happens when you get sucked into a Bill troll?

The catching of the mistakes 
in the explanations to Bill Cunningham,
is the real value of a Bill Cunningham thread.

-- 
pete

[toc] | [prev] | [next] | [standalone]


#27381

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-19 16:59 -0400
Message-ID<k5sf0a$j9h$1@speranza.aioe.org>
In reply to#27371
pete wrote:
> Ian Collins wrote:
>>
>> On 10/18/12 10:36, John Gordon wrote:
>
>>> Sizeof is a keyword, not a function call.
>>> It never needs parentheses.
>>
>> Except, as in this case, where its argument is a type.
>>
>> See what happens when you get sucked into a Bill troll?
>
> The catching of the mistakes
> in the explanations to Bill Cunningham,
> is the real value of a Bill Cunningham thread.

    I'm trying to warn John from getting into the *outgroup* ! He may not 
Know all about C! Like an Eric Sosman or Ian collins &c.

Bill

[toc] | [prev] | [next] | [standalone]


#27382

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-19 17:04 -0400
Message-ID<k5sf7t$jrd$1@speranza.aioe.org>
In reply to#27371
pete wrote:
> Ian Collins wrote:
>>
>> On 10/18/12 10:36, John Gordon wrote:
>
>>> Sizeof is a keyword, not a function call.
>>> It never needs parentheses.
>>
>> Except, as in this case, where its argument is a type.
>>
>> See what happens when you get sucked into a Bill troll?
>
> The catching of the mistakes
> in the explanations to Bill Cunningham,
> is the real value of a Bill Cunningham thread.

People who make mistakes in clc by trying to help and might be flawed are 
looked down on in clc. There is no value to one who doesn't know C or makes 
mistakes in clc.

B

[toc] | [prev] | [next] | [standalone]


#27384

FromBarry Schwarz <schwarzb@dqel.com>
Date2012-10-19 14:14 -0700
Message-ID<2gg3881bei5j93arktd5bo78mnk4nlpkkj@4ax.com>
In reply to#27382
On Fri, 19 Oct 2012 17:04:01 -0400, "Bill Cunningham"
<billcun@suddenlink.net> wrote:

>pete wrote:
>> Ian Collins wrote:
>>>
>>> On 10/18/12 10:36, John Gordon wrote:
>>
>>>> Sizeof is a keyword, not a function call.
>>>> It never needs parentheses.
>>>
>>> Except, as in this case, where its argument is a type.
>>>
>>> See what happens when you get sucked into a Bill troll?
>>
>> The catching of the mistakes
>> in the explanations to Bill Cunningham,
>> is the real value of a Bill Cunningham thread.
>
>People who make mistakes in clc by trying to help and might be flawed are 
>looked down on in clc. There is no value to one who doesn't know C or makes 
>mistakes in clc.

Compared to these ravings, your C code is a model of clarity.

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#27388

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-19 17:31 -0400
Message-ID<k5sgr2$nj8$1@speranza.aioe.org>
In reply to#27384
Barry Schwarz wrote:
> On Fri, 19 Oct 2012 17:04:01 -0400, "Bill Cunningham"
> <billcun@suddenlink.net> wrote:
>
>> pete wrote:
>>> Ian Collins wrote:
>>>>
>>>> On 10/18/12 10:36, John Gordon wrote:
>>>
>>>>> Sizeof is a keyword, not a function call.
>>>>> It never needs parentheses.
>>>>
>>>> Except, as in this case, where its argument is a type.
>>>>
>>>> See what happens when you get sucked into a Bill troll?
>>>
>>> The catching of the mistakes
>>> in the explanations to Bill Cunningham,
>>> is the real value of a Bill Cunningham thread.
>>
>> People who make mistakes in clc by trying to help and might be
>> flawed are looked down on in clc. There is no value to one who
>> doesn't know C or makes mistakes in clc.
>
> Compared to these ravings, your C code is a model of clarity.

    One thing is clear in clc. C expert, computer programmer, nothing to do 
but program ->ingroup. Don't know C, ask questions about it, other things to 
do than program or *don't understand* there's a biggy ->outgroup. Possibly 
to the point of plonk by the ingroup. The ultimate outgrouper.

B

[toc] | [prev] | [next] | [standalone]


#27389

FromKeith Thompson <kst-u@mib.org>
Date2012-10-19 14:54 -0700
Message-ID<ln1ugui0va.fsf@nuthaus.mib.org>
In reply to#27388
"Bill Cunningham" <billcun@suddenlink.net> writes:
[...]
>     One thing is clear in clc. C expert, computer programmer, nothing
> to do but program ->ingroup. Don't know C, ask questions about it,
> other things to do than program or *don't understand* there's a biggy
> ->outgroup. Possibly to the point of plonk by the ingroup. The
> ultimate outgrouper.

Nonsense.  Consider how much time and effort people here have spent
trying to answer your many questions.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#27391

From"Bill Cunningham" <billcun@suddenlink.net>
Date2012-10-19 18:42 -0400
Message-ID<k5sl0f$n6$1@speranza.aioe.org>
In reply to#27389
Keith Thompson wrote:

> Nonsense.  Consider how much time and effort people here have spent
> trying to answer your many questions.

    You maybe Keith and a couple of others. I will try not to post code 
unreadably anymore even if untested like the other day. That was 1-2% 
laziness and the rest not knowing anything about indentation. I always use 
indent and it works great. I don't indent myself. But back to the subject I 
have seen some answer other's questions and I've asked the same question and 
they complain and tell me to get a book or I should already know something. 
It might be lack of patience on their part because I know when dealing with 
me it takes patience.

Bill

[toc] | [prev] | [next] | [standalone]


#27282

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-17 17:47 -0400
Message-ID<507F2780.8040900@verizon.net>
In reply to#27277
On 10/17/2012 05:36 PM, John Gordon wrote:
> In <k5n77p$e5v$1@speranza.aioe.org> "Bill Cunningham" <billcun@suddenlink.net> writes:
> 
>> I don't like const's. They are a nuisance. You can't directly pass string
>> literals to them you want to change.
> 
> Why are you passing something as const when you want to change it?  That's
> kind of the opposite of const.
> 
>> void sort_int(void)
>> {
>>     int num={1,3,6,4,5};
>>     size_t num_len=sizeof num/sizeof (int);
>> }
> 
>> 2. second line of sort_int. num is not a built in type so it doesn't require 
>> parenthesis does it?
> 
> Sizeof is a keyword, not a function call. It never needs parentheses.

The language is case sensitive - that's sizeof, not Sizeof.

The grammar productions involving sizeof are:
	sizeof unary-expression
	sizeof ( type-name )

Thus, parentheses are mandatory when the operand is a type name (as in
sizeof(int) ) rather than a unary expression (as in sizeof num).

[toc] | [prev] | [next] | [standalone]


#27352

Fromtom st denis <tom@iahu.ca>
Date2012-10-19 04:44 -0700
Message-ID<1b439ef8-8616-4c9d-816f-c1e92dae39e1@y8g2000yqy.googlegroups.com>
In reply to#27277
On Oct 17, 5:36 pm, John Gordon <gor...@panix.com> wrote:
> > 2. second line of sort_int. num is not a built in type so it doesn't require
> > parenthesis does it?
>
> Sizeof is a keyword, not a function call. It never needs parentheses.

Not true.  Consider this:

char a;
int x, y, z;

x = sizeof a;
y = sizeof a * 1UL;
z = sizeof (a * 1UL);

What are the values of x/y/z?

So the only time you should use () is when you want the size of an
expression.

:-)

Tom

[toc] | [prev] | [next] | [standalone]


#27353

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-10-19 08:24 -0400
Message-ID<k5rgpm$stg$1@dont-email.me>
In reply to#27352
On 10/19/2012 07:44 AM, tom st denis wrote:
> On Oct 17, 5:36�pm, John Gordon <gor...@panix.com> wrote:
>>> 2. second line of sort_int. num is not a built in type so it doesn't require
>>> parenthesis does it?
>>
>> Sizeof is a keyword, not a function call. It never needs parentheses.
> 
> Not true.  Consider this:
> 
> char a;
> int x, y, z;
> 
> x = sizeof a;
> y = sizeof a * 1UL;
> z = sizeof (a * 1UL);
> 
> What are the values of x/y/z?
> 
> So the only time you should use () is when you want the size of an
> expression.

That's only true when the expression in question does not parse as unary
expression. Each of the following expressions is already a unary
expression, and would therefore not need parentheses if passed to sizeof:

     a
     1UL
     "sizeof"
     _Generic(a, int:5.0, double:5)
     array[1]
     printf("output")
     mystruct.member
     pmystruct->member
     a++
     a--
     (struct tm){.tm_year=112, .tm_month=9, .tm_mday=18}
    ++a
    --a
    &a
    *array
    +a
    -a
    ~a
    !a
    sizeof a
    sizeof(int)
    _Alignof(a)

-- 
James Kuyper

[toc] | [prev] | [next] | [standalone]


#27278

FromBarry Schwarz <schwarzb@dqel.com>
Date2012-10-17 14:39 -0700
Message-ID<1o8u781nrpll3im14bf0019tg1523qv226@4ax.com>
In reply to#27276
On Wed, 17 Oct 2012 17:16:51 -0400, "Bill Cunningham"
<billcun@suddenlink.net> wrote:

>    I have these 3 functions and before I compile I am going to ask about 
>them. This is for qsort. I tried to tackle this once and couldn't get it I 
>think I get it now. I don't like const's. They are a nuisance. You can't 
>directly pass string literals to them you want to change. Maybe that's just 
>the way C is though.

Since changing a string literal is prohibited, you are doomed before
you start.

>
>#include <stdio.h>
>#include <stdlib.h>
>
>int comp(constvoid *a,const void *b)

Wouldn't using cut and paste be easier than retyping?  It would also
eliminate silly errors like parameter 1 as well as provide some clue
that this is your actual code.

>{
>     int *ia=(constint *)a;

Doesn't this generate a diagnostic?  Either you make ia const or you
cast away the const from a.

>     int *ib=(const int *)b;
>     return *ia-*ib;

Are you sure this never overflows?

>}
>
>void print_int_array(int *array,size_t len)
>{
>    size_t i;
>    for (i=0;i<len;i++)

Did you run out of horizontal white space or do you just enjoy
cramming your text together to make it harder to read?

>    printf("%d | ",array[i]);

Still having problems with indenting?

>    putchar('\n');
>}
>
>void sort_int(void)
>{
>    int num={1,3,6,4,5};

Did you mean for num to be an array?

>    size_t num_len=sizeof num/sizeof (int);
>}
>
>1 because of qsorts comp callback function parameters include a const do I 
>need them and can I remove them as I have in the callback?

You didn't remove any const in comp().  Maybe you meant to but are
just posting code of the top of your head.

>2. second line of sort_int. num is not a built in type so it doesn't require 
>parenthesis does it?

What????  num is an object of type int which certainly is built-in. Of
course, you meant for it to be an array of int which is a built-in
aggregate.  But then it would require brackets.


-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


Page 1 of 4  [1] 2 3 4  Next page →

Back to top | Article view | comp.lang.c


csiph-web