Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C and C++ array-to-pointer decay #9

Open
hainest opened this issue Sep 2, 2021 · 0 comments
Open

C and C++ array-to-pointer decay #9

hainest opened this issue Sep 2, 2021 · 0 comments

Comments

@hainest
Copy link

hainest commented Sep 2, 2021

@kupsch Notes

I looked up C function array parameter little used functionality. Here are the details.

When declaring an array parameters to a function in all versions of C and C++ for can use the normal common syntax:

f(T a[])
f(T a[N])

where T is a const/volatile qualified type (also restrict qualified for C). These parameter types decay to the type T*.

C99 and later versions of C allow the additional syntax

f(T a[OPT_KEYWORDS N])
f(T a[OPT_KEYWORDS *]) same as f(T a[OPT_KEYWORDS])

where OPT_KEYWORDS are used to require a array size and to add qualifiers to the pointer itself as opposed to the type of the pointer where the qualifiers are part of T. They can be one or more of the following:

static - hint: a is not NULL with at least N elements
const - type of a inside the function is Tconst
volatile - type of a inside the function is T
volatile
restrict - type of a inside the function is T*restrict

The * indicates unknown size.

For example, the declaration

f(volatile int a[static const restrict 10])

would treat the type of a in the function f as if it were declared:

volatile int * const restrict a;

with the value of a being not null and containing at least 10 elements.


There is a lot more to mention about this, but I wanted to record Jim's notes first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant