Change in osmo-msc[master]: rename gsm_encr to geran_encr, it is only applicable on GERAN

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Nov 30 18:23:43 UTC 2018


Neels Hofmeyr has posted comments on this change. ( https://gerrit.osmocom.org/12039 )

Change subject: rename gsm_encr to geran_encr, it is only applicable on GERAN
......................................................................


Patch Set 3:

(1 comment)

can i has +2?

https://gerrit.osmocom.org/#/c/12039/3/src/libmsc/gsm_04_08.c
File src/libmsc/gsm_04_08.c:

https://gerrit.osmocom.org/#/c/12039/3/src/libmsc/gsm_04_08.c@1666
PS3, Line 1666: 	conn->geran_encr = (struct geran_encr){};
> Or you can only do that at same time you declare the struct variable?
sorry guys, it's going to stay this way. I'm already using this scheme throughout all code I write, and it is the single best method. Here is my reasoning:

- memset() is the byte hacking way and I don't like it. In practice, clearing out is always 0, and even '\0' is 0, and NULL is 0, and false is 0, but that's just incidental. Semantically, each type has its own constructor default value. Using memset() totally brushes over that concept; which works out fine in practice, but I will use compiler provided default values wherever I can and avoid memset.

- just 'var = {0}' doesn't work, you need to supply the type name to the compiler (unless it is a new variable declaration init, which this is not; see examples below).

- the struct variable is part of ran_conn, I need to here clean out one part of that. It does not make sense to declare a new local variable for that. (see examples below)

- to write "{0}" means that I indicate the first item's value to be zero. Doing "{}" is the more general way that achieves to zero all items, no matter what type they are. Let me illustrate...

With this, writing {0} is fine, since the first element is an int:

  struct foo {
    int a;
    int b[3];
  }

  struct foo my_foo = {0}; // initialize a = 0, the rest as zero

But what about this:

  struct bar {
     struct {
        int a;
     } sub;
     char c[3];
  }

Doesn't work:

  struct bar my_bar = {0};

Would have to be one of:

  struct bar my_bar = { {0} };
  struct bar my_bar = { .sub = {0} };
  struct bar my_bar = { .c = {0, 0, 0} };
  struct bar my_bar = { .c = {} };

But I don't WANT any specific value! Just zero all!
The Generally Always Working Best (TM) way to approach this is:

  struct bar my_bar = {};

All items are zeroed without needing to know anything about its structure.

Why this (struct bar){} notation here? because I have

  struct moo {
     struct bar item;
  };

  void my_func(struct moo *m)
  {
      m->item = (struct bar){};
  }

This is the way it should be done, and you will not convince me otherwise, sorry



-- 
To view, visit https://gerrit.osmocom.org/12039
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Idc7ca9da1aa13ae16f5db2cb1024676cbc770820
Gerrit-Change-Number: 12039
Gerrit-PatchSet: 3
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Comment-Date: Fri, 30 Nov 2018 18:23:43 +0000
Gerrit-HasComments: Yes
Gerrit-HasLabels: No
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181130/28ebe650/attachment.htm>


More information about the gerrit-log mailing list