Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <v6moe3$21n94$2@dont-email.me>
Deutsch   English   Français   Italiano  
<v6moe3$21n94$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: David Brown <david.brown@hesbynett.no>
Newsgroups: comp.lang.c
Subject: =?UTF-8?Q?Re=3A_technology_discussion_=E2=86=92_does_the_world_need?=
 =?UTF-8?B?IGEgIm5ldyIgQyA/?=
Date: Wed, 10 Jul 2024 21:46:11 +0200
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <v6moe3$21n94$2@dont-email.me>
References: <v66eci$2qeee$1@dont-email.me> <v68dsm$37sg2$1@dont-email.me>
 <87wmlzvfqp.fsf@nosuchdomain.example.com> <v6ard1$3ngh6$4@dont-email.me>
 <v6b0jv$3nnt6$1@dont-email.me> <87h6d2uox5.fsf@nosuchdomain.example.com>
 <v6d779$6rk5$2@dont-email.me> <v6e76u$c0i9$1@dont-email.me>
 <v6esqm$fian$2@dont-email.me> <v6f7vg$hgam$1@dont-email.me>
 <20240707164747.258@kylheku.com> <v6gl83$s72a$1@dont-email.me>
 <v6h8ao$ur1v$1@dont-email.me> <v6jhk3$1drd6$1@dont-email.me>
 <v6jiud$1dsjb$1@dont-email.me> <877cdur1z9.fsf@bsb.me.uk>
 <v6joi4$1epoj$1@dont-email.me> <871q42qy33.fsf@bsb.me.uk>
 <v6k6i0$1h4d3$1@dont-email.me> <87ed82p28y.fsf@bsb.me.uk>
 <v6m03l$1tf05$1@dont-email.me> <87r0c1nzjj.fsf@bsb.me.uk>
 <v6m7ae$1v125$1@dont-email.me> <v6ma1d$1vfv2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jul 2024 21:46:12 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c985da9317a18f8af2811d5dea43797f";
	logging-data="2153764"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19ObWLBo13ecRoZaMaZdDu6O2SVW9zYRF4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vowGntJRRqa+Gt8R8tNTlpjj3ds=
In-Reply-To: <v6ma1d$1vfv2$1@dont-email.me>
Content-Language: en-GB
Bytes: 4642

On 10/07/2024 17:40, bart wrote:
> On 10/07/2024 15:54, Janis Papanagnou wrote:
> 
>> Values passed (including values of pointers [used for arrays]) are
>> handled (in the functions) as copies and cannot change the original
>> entities (values or dereferenced objects) in the calling environment.
>>
>> To make it possible to change entities in the calling environment
>> in "C" you have to implement the necessary indirection by pointers.
> 

>> Your insistence is amazing. 
> /I/ am amazed at everyone's insistence that there is nothing remarkable 
> about this, and that it is nothing at all like pass-by-reference.

Nobody has said anything close to "it is nothing at all like 
pass-by-reference".  Many people have made it clear that using pointers 
- explicitly, or implicitly via the language's automatic decay of array 
and function expressions to pointers in certain contexts, can be used to 
give a similar effect to passing by reference.  Indeed, it is precisely 
the reason C does not have "pass by reference" - it is not needed, as 
you can conveniently use pointers and "pass by value".

> 
> So, how do I write F in C so that the caller's data is unchanged?

You use a type that you /can/ pass as an argument in C.  You can't pass 
arrays to functions, or return them.  A convenient method is to wrap the 
array in a struct :

typedef struct {
	uint8_t data[4];
} vector;

If you want to pass around copies of arrays without a fixed predefined 
size in C, you need to do it all manually - allocate space for copies, 
copy them, pass the pointer to the first element and the size of the 
array.  It is one of the things that C does not do for you and you need 
to do manually, just like most memory management.

> 
> Sure, true pass-by-reference has some extra properties, but if I wanted 
> to duplicate the behaviour of the above in my language, I have to use 
> pass-by-reference.
> 
> In C you get that behaviour anyway (possibly to the surprise of many), 
> in a language which only has pass-by-value, and without needing explicit 
> pointers.

I really don't think any of this is a surprise to many people who make 
more than a basic effort to learn the language.  It is not hard to 
understand, as long as you don't fixate on wrong interpretations of how 
it all works in C.

> 
> That really is remarkable. And not unsafe at all!
> 

C is a language that requires more responsibility by the programmer for 
things that higher level languages handle automatically.  That's the way 
the language is.  If you don't understand it, you'll make mistakes.

(To be clear here - people have been explaining the facts, not opinions. 
  Some people here would surely have liked C to be able to pass arrays 
into and out of functions like other C objects.)