Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Nullable/Notnull : syntax proposal

Reply
Thread Tools

Nullable/Notnull : syntax proposal

 
 
sarnold@free.fr
Guest
Posts: n/a
 
      11-04-2007
Hello,

I am proposing to create two new keywords for C, 'notnull' and
'nullable'.
Their meaning is a sort of 'design by contract', ensuring some rules
are
verified at compile-time. It should not require additional runtime-
checks
to be implemented.
I have posted my description of how it should work at this URL:
http://sarnold.free.fr/wordpress/?p=71
Please read it and tell me what you think of it.

Regards,
Stéphane A.

 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      11-04-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> Hello,
>
> I am proposing to create two new keywords for C, 'notnull' and
> 'nullable'.
> Their meaning is a sort of 'design by contract', ensuring some rules
> are
> verified at compile-time. It should not require additional runtime-
> checks
> to be implemented.
> I have posted my description of how it should work at this URL:
> http://sarnold.free.fr/wordpress/?p=71
> Please read it and tell me what you think of it.
>
> Regards,
> Stéphane A.


Simplify it. There is no need for "nullable" since it's already there.

In addition I think it's a silly idea. Just wrap malloc to do what you want to
do rather than have the assignment to a notnull variable. Much more
efficient. Otherwise every time you assign to a notnull the system will
be performing these checks.

 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      11-04-2007
(E-Mail Removed) writes:

> I am proposing to create two new keywords for C, 'notnull' and
> 'nullable'.


How does this relate to the GCC extension that provides for a
"nonnull" attribute on function arguments? Here is the
documentation for the GCC extension:

`nonnull (ARG-INDEX, ...)'
The `nonnull' attribute specifies that some function parameters
should be non-null pointers. For instance, the declaration:

extern void *
my_memcpy (void *dest, const void *src, size_t len)
__attribute__((nonnull (1, 2)));

causes the compiler to check that, in calls to `my_memcpy',
arguments DEST and SRC are non-null. If the compiler determines
that a null pointer is passed in an argument slot marked as
non-null, and the `-Wnonnull' option is enabled, a warning is
issued. The compiler may also choose to make optimizations based
on the knowledge that certain function arguments will not be null.

If no argument index list is given to the `nonnull' attribute, all
pointer arguments are marked as non-null. To illustrate, the
following declaration is equivalent to the previous example:

extern void *
my_memcpy (void *dest, const void *src, size_t len)
__attribute__((nonnull));

By the way, comp.std.c would be a better place to discuss this.
Followups set.
--
char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa6 7f6aaa,0xaa9aa9f6,0x11f6},*p
=b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)break;else default:continue;if(0)case 1utchar(a[i&15]);break;}}}
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      11-04-2007
(E-Mail Removed) wrote:
>
> Hello,
>
> I am proposing to create two new keywords for C, 'notnull' and
> 'nullable'.
> Their meaning is a sort of 'design by contract', ensuring some rules
> are
> verified at compile-time. It should not require additional runtime-
> checks
> to be implemented.
> I have posted my description of how it should work at this URL:
> http://sarnold.free.fr/wordpress/?p=71
> Please read it and tell me what you think of it.


I don't need it.
I don't want it.
I don't like it.
I'm surprised it isn't already in C99.

--
pete
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      11-04-2007
(E-Mail Removed) wrote:
> Hello,
>
> I am proposing to create two new keywords for C, 'notnull' and
> 'nullable'.
> Their meaning is a sort of 'design by contract', ensuring some rules
> are
> verified at compile-time. It should not require additional runtime-
> checks
> to be implemented.
> I have posted my description of how it should work at this URL:
> http://sarnold.free.fr/wordpress/?p=71
> Please read it and tell me what you think of it.
>
> Regards,
> Stéphane A.
>


You can assert a parameter not being null in standard C by

int function(int MyTable[static 1]);

This means that the parameter MyTable has at least one
element, i.e. it can't be NULL.

True, it is NOT a GREAT syntax but it is standard.

jacob
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      11-04-2007
(E-Mail Removed) wrote:

> I am proposing to create two new keywords for C, [ ... ]


Since you are apparently proposing changes to the language the correct
group for that would be <news:comp.std.c>


 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      11-04-2007
santosh <(E-Mail Removed)> writes:

> (E-Mail Removed) wrote:
>
>> I am proposing to create two new keywords for C, [ ... ]

>
> Since you are apparently proposing changes to the language the correct
> group for that would be <news:comp.std.c>


He is asking for C programmer's opinions. So here is perfectly valid.
 
Reply With Quote
 
=?iso-2022-kr?q?=1B=24=29CHarald_van_D=0E=29=26=0Fk?=
Guest
Posts: n/a
 
      11-04-2007
On Sun, 04 Nov 2007 18:53:49 +0100, jacob navia wrote:
> (E-Mail Removed) wrote:
>> Hello,
>>
>> I am proposing to create two new keywords for C, 'notnull' and
>> 'nullable'.
>> Their meaning is a sort of 'design by contract', ensuring some rules
>> are
>> verified at compile-time. It should not require additional runtime-
>> checks
>> to be implemented.
>> I have posted my description of how it should work at this URL:
>> http://sarnold.free.fr/wordpress/?p=71 Please read it and tell me what
>> you think of it.
>>
>> Regards,
>> Stéphane A.
>>
>>

> You can assert a parameter not being null in standard C by
>
> int function(int MyTable[static 1]);


Almost, but not quite.

> This means that the parameter MyTable has at least one element, i.e. it
> can't be NULL.


It means you can't call function with the result of malloc(1), while
occasionally (okay, rarely) that's actually useful.
 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      11-04-2007
Harald van Dijk wrote:
> On Sun, 04 Nov 2007 18:53:49 +0100, jacob navia wrote:
>> (E-Mail Removed) wrote:
>>> Hello,
>>>
>>> I am proposing to create two new keywords for C, 'notnull' and
>>> 'nullable'.
>>> Their meaning is a sort of 'design by contract', ensuring some rules
>>> are
>>> verified at compile-time. It should not require additional runtime-
>>> checks
>>> to be implemented.
>>> I have posted my description of how it should work at this URL:
>>> http://sarnold.free.fr/wordpress/?p=71 Please read it and tell me what
>>> you think of it.
>>>
>>> Regards,
>>> Stéphane A.
>>>
>>>

>> You can assert a parameter not being null in standard C by
>>
>> int function(int MyTable[static 1]);

>
> Almost, but not quite.
>
>> This means that the parameter MyTable has at least one element, i.e. it
>> can't be NULL.

>
> It means you can't call function with the result of malloc(1), while
> occasionally (okay, rarely) that's actually useful.


Can you explain what you say?

I didn't understand what you are saying.
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      11-05-2007
On Sun, 04 Nov 2007 09:23:20 -0800, (E-Mail Removed) wrote in
comp.lang.c:

> Hello,
>
> I am proposing to create two new keywords for C, 'notnull' and
> 'nullable'.
> Their meaning is a sort of 'design by contract', ensuring some rules
> are
> verified at compile-time. It should not require additional runtime-
> checks
> to be implemented.
> I have posted my description of how it should work at this URL:
> http://sarnold.free.fr/wordpress/?p=71
> Please read it and tell me what you think of it.


No. Because...no.

Not even if you made them _Notnull and _Nullable, which I'm fairly
sure the committee would insist on to keep them in the implementation
namespace to avoid breaking existing code.

Just no.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python dot-equals (syntax proposal) Jabapyth Python 40 05-03-2010 05:15 PM
multiple return values (new syntax proposal) aleksandar.ristovski@gmail.com C++ 8 09-10-2006 01:05 AM
IL Generator syntax proposal John Lam Ruby 8 12-07-2005 12:56 AM
RE: pre-PEP: Suite-Based Keywords - syntax proposal Robert Brewer Python 13 04-20-2005 06:21 PM
PEP-318, billion-and-first syntax proposal Tim Hochberg Python 0 08-10-2004 07:38 PM



Advertisments