A Minor Issue Report: Extra const Keyword in PragmaName zName

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

A Minor Issue Report: Extra const Keyword in PragmaName zName

Richard Green
I believe the struct PragmaName (in pragma.h) has an extra 'const'
keyword for zName, in Version 3.26.0 (2018-12-01); probably has no effect.

Currently,

/* Definitions of all built-in pragmas */
typedef struct PragmaName {
   const char *constzName; /* Name of pragma */
   u8 ePragTyp;             /* PragTyp_XXX value */
   u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
   u8 iPragCName;           /* Start of column names in pragCName[] */
   u8 nPragCName;           /* Num of col names. 0 means use pragma name */
   u64 iArg;                /* Extra argument */
} PragmaName;


Probably should be,

/* Definitions of all built-in pragmas */
typedef struct PragmaName {
   const char *zName;       /* Name of pragma */
   u8 ePragTyp;             /* PragTyp_XXX value */
   u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
   u8 iPragCName;           /* Start of column names in pragCName[] */
   u8 nPragCName;           /* Num of col names. 0 means use pragma name */
   u64 iArg;                /* Extra argument */
} PragmaName;



Thank you,

Richard Green


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] A Minor Issue Report: Extra const Keyword in PragmaName zName

Hick Gunter
There is a significant difference

A "const char *" is a (mutable) pointer to an immutable char. You can make it point somewhere else.

A "char * const" is an immutable pointer to a mutable char. You can change the char it is pointing to.

A "const char * const" is an immutable pointer to an immutable char. You can't change anything.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[hidden email]] Im Auftrag von Richard Green
Gesendet: Montag, 31. Dezember 2018 00:11
An: [hidden email]
Betreff: [EXTERNAL] [sqlite] A Minor Issue Report: Extra const Keyword in PragmaName zName

I believe the struct PragmaName (in pragma.h) has an extra 'const'
keyword for zName, in Version 3.26.0 (2018-12-01); probably has no effect.

Currently,

/* Definitions of all built-in pragmas */ typedef struct PragmaName {
   const char *constzName; /* Name of pragma */
   u8 ePragTyp;             /* PragTyp_XXX value */
   u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
   u8 iPragCName;           /* Start of column names in pragCName[] */
   u8 nPragCName;           /* Num of col names. 0 means use pragma name */
   u64 iArg;                /* Extra argument */ } PragmaName;


Probably should be,

/* Definitions of all built-in pragmas */ typedef struct PragmaName {
   const char *zName;       /* Name of pragma */
   u8 ePragTyp;             /* PragTyp_XXX value */
   u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
   u8 iPragCName;           /* Start of column names in pragCName[] */
   u8 nPragCName;           /* Num of col names. 0 means use pragma name */
   u64 iArg;                /* Extra argument */ } PragmaName;



Thank you,

Richard Green


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick | Software Engineer | Scientific Games International GmbH | Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: A Minor Issue Report: Extra const Keyword in PragmaName zName

Richard Damon
In reply to this post by Richard Green
On 12/30/18 6:10 PM, Richard Green wrote:

> I believe the struct PragmaName (in pragma.h) has an extra 'const'
> keyword for zName, in Version 3.26.0 (2018-12-01); probably has no
> effect.
>
> Currently,
>
> /* Definitions of all built-in pragmas */
> typedef struct PragmaName {
>   const char *constzName; /* Name of pragma */
>   u8 ePragTyp;             /* PragTyp_XXX value */
>   u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
>   u8 iPragCName;           /* Start of column names in pragCName[] */
>   u8 nPragCName;           /* Num of col names. 0 means use pragma
> name */
>   u64 iArg;                /* Extra argument */
> } PragmaName;
>
>
> Probably should be,
>
> /* Definitions of all built-in pragmas */
> typedef struct PragmaName {
>   const char *zName;       /* Name of pragma */
>   u8 ePragTyp;             /* PragTyp_XXX value */
>   u8 mPragFlg;             /* Zero or more PragFlg_XXX values */
>   u8 iPragCName;           /* Start of column names in pragCName[] */
>   u8 nPragCName;           /* Num of col names. 0 means use pragma
> name */
>   u64 iArg;                /* Extra argument */
> } PragmaName;
>
>
>
> Thank you,
>
> Richard Green

const char *constzName;

is defining a member constzName, so changing that would require changing
everywhere it is used.

if it was

const char *const zName; // Note extra space

Then that is declaring that zName is an immutable pointer to a immutable
string/character, which is actually likely true, as the code shouldn't
be changing the names of pragmas.

Your modified definition says that the code is allowed to poke through
zName and change the string representing the pragma.

--
Richard Damon

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: A Minor Issue Report: Extra const Keyword in PragmaName zName

Dominique Devienne
On Wed, Jan 2, 2019 at 1:47 PM Richard Damon <[hidden email]>
wrote:

> On 12/30/18 6:10 PM, Richard Green wrote:
> const char *const zName; // Note extra space
>
> Then that is declaring that zName is an immutable pointer to a immutable
> string/character, which is actually likely true, as the code shouldn't
> be changing the names of pragmas.
>

Yeah, but a const T*const pointer must be initialized.
(unless it's a function argument, in which case it's the "caller" doing the
init, somehow).
Otherwise how else would you assign a value to that const pointer?

So as-is as a struct field, it wouldn't make sense.
C has no constructor like C++ has, to perform the assignment in the
"initializer list"
of the Ctor (i.e. between : and { ) (maybe aggregate initialization can,
that's as close
to a Ctor C has. May that would work...)

In Java you can, it's called a "blank final", i.e. compiler tracks at
compile-time when
the variable is first assigned, allowing that one, and errors out at all
other assignments (or if not initialized at all).

But in C/C++, I logically don't see how that makes sense. Haven't tried it
recently though :). --DD
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] Re: A Minor Issue Report: Extra const Keyword in PragmaName zName

Hick Gunter
Please note that this is in a typedef. The initialization needs to happen when a structure of this type is declared.

const PragmaName g_mypragma = { "mypragma", ...};

Would allow the compiler to put *both* the string "mypragma" *and* the structure g_mypragma into (read only) "string space", with the linker/loader calculating the actual value of the pointer.

-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:[hidden email]] Im Auftrag von Dominique Devienne
Gesendet: Mittwoch, 02. Jänner 2019 14:22
An: SQLite mailing list <[hidden email]>
Betreff: [EXTERNAL] Re: [sqlite] A Minor Issue Report: Extra const Keyword in PragmaName zName

On Wed, Jan 2, 2019 at 1:47 PM Richard Damon <[hidden email]>
wrote:

> On 12/30/18 6:10 PM, Richard Green wrote:
> const char *const zName; // Note extra space
>
> Then that is declaring that zName is an immutable pointer to a
> immutable string/character, which is actually likely true, as the code
> shouldn't be changing the names of pragmas.
>

Yeah, but a const T*const pointer must be initialized.
(unless it's a function argument, in which case it's the "caller" doing the init, somehow).
Otherwise how else would you assign a value to that const pointer?

So as-is as a struct field, it wouldn't make sense.
C has no constructor like C++ has, to perform the assignment in the "initializer list"
of the Ctor (i.e. between : and { ) (maybe aggregate initialization can, that's as close to a Ctor C has. May that would work...)

In Java you can, it's called a "blank final", i.e. compiler tracks at compile-time when the variable is first assigned, allowing that one, and errors out at all other assignments (or if not initialized at all).

But in C/C++, I logically don't see how that makes sense. Haven't tried it recently though :). --DD _______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick | Software Engineer | Scientific Games International GmbH | Klitschgasse 2-4, A-1130 Vienna | FN 157284 a, HG Wien, DVR: 0430013 | (O) +43 1 80100 - 0

May be privileged. May be confidential. Please delete if not the addressee.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users