Can adding a return parameter to void method break existing functionality?

Currently, I am creating some end to end tests for an API and have a method that would be perfect to use for a test except for the fact that it has a return type of void. If I were to change the return type to List, could this possibly break existing functionality somewhere within the system? My current thoughts are that all code that calls the method will not be affected as they are not using the method to assign any value to a variable. Are there any cases in which this is not true?

This is for a legacy code base, so unfortunately I am stuck with it. The codebase is too vast for me to look up all instances of code that could be affected by this change.

Передача указателя на void функцию в качестве аргумента

Вечно путаю синтаксис…

Есть функция:

void DoSMTH(int a1, int b1){     // Делаю что-то с a1 и b1 } 

Есть функция Вызывальщик

int DoSMTHwithSMTH(/* Что здесь? */){        /* ЗДЕСЬ ВЫЗОВ DoSMTH(a2, b2) */ } 

Главный поток:

int main(){     return DoSMTHwithSMTH(/* ЧТО ЗДЕСЬ? */) } 

P.S. Код вверху – пример, если хотите – можете привести свой

Pointer to void in C preprocessor

I read this source(https://github.com/lattera/glibc/blob/master/stdio-common/vfprintf.c) and find some interesting lines, which I not fully understand:

#ifdef SHARED /* 'int' is enough and it saves some space on 64 bit systems.  */ # define JUMP_TABLE_TYPE const int # define JUMP_TABLE_BASE_LABEL do_form_unknown # define REF(Name) &&do_##Name - &&JUMP_TABLE_BASE_LABEL # define JUMP(ChExpr, table)                              \   do                                      \ {                                     \   int offset;                                 \   void *ptr;                                  \   spec = (ChExpr);                            \   offset = NOT_IN_JUMP_RANGE (spec) ? REF (form_unknown)          \     : table[CHAR_CLASS (spec)];                       \   ptr = &&JUMP_TABLE_BASE_LABEL + offset;                 \   goto *ptr;                                  \ }                                     \   while (0)   ...  #define STEP0_3_TABLE                                 \ /* Step 0: at the beginning.  */                          \ static JUMP_TABLE_TYPE step0_jumps[30] =                      \ {                                         \   REF (form_unknown),                             \   REF (flag_space),     /* for ' ' */                     \   REF (flag_plus),      /* for '+' */                     \   REF (flag_minus),     /* for '-' */                     \   REF (flag_hash),      /* for '<hash>' */                \   REF (flag_zero),      /* for '0' */                     \   REF (flag_quote),     /* for '\'' */                    \   REF (width_asterics), /* for '*' */                     \   REF (width),      /* for '1'...'9' */               \   REF (precision),      /* for '.' */                     \   REF (mod_half),       /* for 'h' */                     \   ... 

I wrote simple example and understand that this line &&do_##Name cast do_##Name to pointer to void. But I don’t understand how works pointer arythmetis in this case: #define REF(Name) &&do_##Name – &&JUMP_TABLE_BASE_LABEL Can someone write simple explane? Or write some link to Internet resource where I can read about this technique best regards.

Corsair VOID Pro Sidetone

I just made the switch from Windows 10 to Ubuntu 18.04.2 LTS, and I was immediately greeted with the sidetone in my Corsair VOID Pro kicking back on. I can hear everything my microphone picks up which is pretty annoying. I heard that there wasn’t much support for peripherals in Linux, but I was hoping there was some way to at least turn off the sidetone for the headset. Any solutions?

Headset on Amazon

Не знаю, как задать переменную типа void** +Собрать запустить всё в main

#include <iostream> #include <string.h> #include <malloc.h> #include <math.h> #include <TCHAR.h> #include <conio.h> using namespace std; typedef enum _comp {     diod = 1,     lamp,     motor,     power,     time,     energy } Comp;   typedef struct _diod {     Comp kind;     int q, e; }Diod;  typedef struct _lamp {     Comp kind;     int q, e; }Lamp;  typedef struct _motor {     Comp kind;     int q, e; }Motor;  typedef struct _power {     Comp kind;     int e; }Power;  typedef struct _time {     Comp kind;     int t; }Time;  typedef struct _energy {     Comp kind;     int q, e; }Energy;  void* ppCompArray[]={NULL,NULL,NULL,NULL,NULL,NULL}; Comp comp_kind = *((Comp*)ppCompArray[0]);  Diod* CalcDiod() {     Diod* p = (Diod*)malloc(sizeof(Diod));     int a,b;     cout << "Enter Kol-vo;";     cin >> a;     cout << " Enter power;";     cin >> b;     p->kind = diod;     p->e = a*b;     return p; }  Lamp* CalcLamp() {     Lamp* p = (Lamp*)malloc(sizeof(Lamp));     int a,b;     cout << "Enter Kol-vo;";     cin >> a;     cout << " Enter power;";     cin >> b;     p->kind = lamp;     p->e = a*b;     return p; }  Motor* CalcMotor() {     Motor* p = (Motor*)malloc(sizeof(Motor));     int a,b;     cout << "Enter Kol-vo;";     cin >> a;     cout << " Enter power;";     cin >> b;     p->kind = motor;     p->e = a*b;     return p; }  Power* CalcPower() {     Power* p = (Power*)malloc(sizeof(Power));     int a,b;     cout << "Enter Kol-vo;";     cin >> a;     cout << " Enter power;";     cin >> b;     p->kind = power;     p->e = a*b;     return p; }  Time* CalcTime() {     Time* p = (Time*)malloc(sizeof(Time));     int a,b;     cout << "Enter Kol-vo;";     cin >> a;     cout << " Enter power;";     cin >> b;     p->kind = time;     p->t = a*b;     return p; }  Energy* CalcEnergy() {     Energy* p = (Energy*)malloc(sizeof(Energy));     int a,b;     cout << "Enter Kol-vo;";     cin >> a;     cout << " Enter power;";     cin >> b;     p->kind = energy;     p->e = a*b;     return p; }   int AddComp(void** ppComp) {  int counter = 0;  bool quit = false;  while(!quit)  {  if(counter > 3)  return counter;  printf("Enter Figure Kind: \n");  printf("1 - diod;\n");  printf("2 - lamp;\n");  printf("3 - motor;\n");   printf("4 - power;\n");    printf("5 - time;\n");  printf("6 - energy;\n");  printf("e - Exit.\n\n");   int key;  switch(key)  {  case '1':  {   Diod* c = CalcDiod();  if(c != NULL)   {  ppComp[counter] = c;  counter++;  }  break;  }  case '2':  {   Lamp* r = CalcLamp();  if(r != NULL)   {      ppComp[counter] = r;   counter++;  }  break;  }  case '3':  {  Motor* w = CalcMotor();  if(w != NULL)   {  ppComp[counter] = w;  counter++;  } break;  }    case '4':  {  Power* d = CalcPower();  if(d != NULL)   {  ppComp[counter] = d;  counter++;  } break;  }    case '5':  {  Time* f = CalcTime();  if(f != NULL)   {  ppComp[counter] = f;  counter++;  } break;  }    case '6':  {  Energy* s = CalcEnergy();  if(s != NULL)   {  ppComp[counter] = s;  counter++;  }   break;   }  case '7':  {  printf("%d elements were created.\n\n", counter);  return counter;  break;  default:  printf("Enter correct number. Try again of Exit.\n");  }  }  printf("%d elements were created", counter);  return counter;  } }  float GetComP(void** ppComp, int count) {  float P = 0;   for(int i = 0; i < count; i++)  {  void* p = ppComp[i];    Comp kind = *((Comp*)p);  switch(kind)  {  case diod:  P += (float)((Diod*)p)->e;  break;  case lamp:  P += (float)((Lamp*)p)->e;  break;   case motor:  P += (float)((Motor*)p)->e;  break;   case power:  P += (float)((Power*)p)->e;  break;   case time:  P += (float)((Time*)p)->t;  break;   case energy:  P += (float)((Energy*)p)->e;  break;   default:   printf("Error in calculation of Power!!! \n");  return 0;  }  }  return P; }  int _tmain(int argc, _TCHAR* argv[]) {      cin >> ppCompArray[0];     void* l -   int realCount = 0; float s = GetComP(ppCompArray,realCount);  printf("Power of element: %d", s);  return 0; }  

Adjacency list in c with void functions

Incomplete code are shown as follow:

typedef struct _Node{     char name[100];     int id;     struct _Node *next; } Node;  typedef struct _Adj_Row{     Node *header;     struct _Adj_Row *next; } Adj_Row;  typedef struct{     Adj_Row *header; } Adj_List;  void InsertNode(Adj_List *g, int x, char name[]){     Node* new_node = malloc(sizeof(Node));     new_node -> id = x;     **strcpy (new_node->name,name);**     new_node -> next = NULL;      if (g->header == NULL){         Adj_Row *p = g->header;         p->header = new_node ;         p->next = NULL;     }     else{         Node *c = (g->header)->header;         While(c->next!=NULL){             if ( c->id == x ){                 printf("\nDuplicated node.");             }             if ( c->next->id > x){                 Node *temp = c->next;                 c->next = new_node;                 new_node->next = temp;                 break;             }             c = c->next;         }     } }  int main(){     char command[100];     Adj_List g;     g.header=NULL;      while (scanf("%s", command)){         if (strcmp(command, "InsertNode")==0){             int x;             char name[100];             scanf("%d %s", &x, name);             InsertNode(&g, x, name);         }         else if (strcmp(command, "InsertEdge")==0){             int x, y;             scanf("%d %d", &x, &y);             InsertEdge(&g, x, y);         }     }     return 0; } 

I am struggling with the implementation of InsertNode. After I have created a new node, I am not sure how to initialize it in the Adj_Row and the Adj_list as defined. The InsertNode also has the following requirment:

1.If the id of the node has been existed already, output “Duplicated node.” on screen.

2.The id of the nodes is an integer which may not start from 0 and may not be in ascending order.

3.The node should be stored in the ascending order of the id of the node.

I have tried to implement, but I don’t exactly know what the problem is.

Sample input:

InsertNode 1 Shop

InsertNode 2 Bakery

InsertNode 0 Home

InsertNode 3 Bank

The output would be:

Home

Shop

Bakery

Bank

My app crushing bec of: ‘void android.media.MediaPlayer.stop()’ on a null object reference

Everything works fine in my app but when i press back button (i mean exit app) the app is crushing. And i don’t know why? I tried a couple solitions but nothing works. It’s a sounds/ringtones application.

I’m having some problems when i clicked back button. It tells me that it’s unable to pause the activity. What does that mean?

Here my codes

mainActivity

public class MainActivity extends AppCompatActivity {     public MediaPlayer mp;     DrawerLayout mDrawerLayout;     NavigationView mNavigationView;     FragmentManager mFragmentManager;     FragmentTransaction mFragmentTransaction;       @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          toolbarTabs();         sidebar();         externalStorageAccess();      }      // Creates sidebar and sets onClickListeners     public void sidebar(){         mNavigationView = (NavigationView) findViewById(R.id.navigationView);         mNavigationView.setItemIconTintList(null);         mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {             @Override             public boolean onNavigationItemSelected(MenuItem menuItem) {                 mDrawerLayout.closeDrawers();                  switch (menuItem.getItemId()){                     case R.id.sounds:                         FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();                         xfragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();                         break;                      case R.id.share:                         Intent shareIntent = new Intent(Intent.ACTION_SEND);                         shareIntent.setType("text/plain");                         shareIntent.putExtra(Intent.EXTRA_SUBJECT, getText(R.string.app_name));                         shareIntent.putExtra(Intent.EXTRA_TEXT, getText(R.string.share_text) + " " +  getText(R.string.app_name) + "\n\n" + getText(R.string.playstore_link));                         startActivity(Intent.createChooser(shareIntent,  getText(R.string.share_via)));                         break;                  }                 return false;             }          });     }       // Is listening which sound on Tab1 has been clicked     public void TabOneItemClicked(int position) {         cleanUpMediaPlayer();         mp=MediaPlayer.create(MainActivity.this, Tab1.soundfiles[position]);         mp.start();      }      // Is listening which sound on Tab2 has been clicked     public void TabTwoItemClicked(int position) {         cleanUpMediaPlayer();         mp=MediaPlayer.create(MainActivity.this, Tab2.soundfiles[position]);         mp.start();     }      // Is listening which sound on Tab3 has been clicked     public void TabThreeItemClicked ( int position){         cleanUpMediaPlayer();         mp=MediaPlayer.create(MainActivity.this, Tab3.soundfiles[position]);         mp.start();     }       // Cleans MediaPlayer     public void cleanUpMediaPlayer() {         if (mp != null) {             try {                 mp.stop();                 mp.release();                 mp = null;             } catch (Exception e) {                 e.printStackTrace();                 Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_LONG).show();              }         }     }      // Access external storage     public void externalStorageAccess(){         final File FILES_PATH = new File(Environment.getExternalStorageDirectory(), "Android/data/"+ getText(R.string.package_name) +"/files");         if (Environment.MEDIA_MOUNTED.equals(                 Environment.getExternalStorageState())) {             if (!FILES_PATH.mkdirs()) {                 Log.w("error", "Could not create " + FILES_PATH);             }         } else {             Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_LONG).show();             finish();         }     }      // Creates toolbar Tabs     public void toolbarTabs(){         mFragmentManager = getSupportFragmentManager();         mFragmentTransaction = mFragmentManager.beginTransaction();         mFragmentTransaction.replace(R.id.containerView, new TabFragment()).commit();         mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);         android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);         ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name,                 R.string.app_name);         mDrawerLayout.setDrawerListener(mDrawerToggle);         mDrawerToggle.syncState();     }       @Override     protected void onPause() {         super.onPause();         stopMediaPlayer();     }      public void stopMediaPlayer()     {         mp.stop();     } }   

And this is my error logs. I’ve been getting errors when I build for my Android device.

    java.lang.RuntimeException: Unable to pause activity {com.app.trying/com.app.trying.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.stop()' on a null object reference         at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3735)         at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3701)         at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3675)         at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3649)         at android.app.ActivityThread.-wrap16(ActivityThread.java)         at android.app.ActivityThread$  H.handleMessage(ActivityThread.java:1487)         at android.os.Handler.dispatchMessage(Handler.java:102)         at android.os.Looper.loop(Looper.java:154)         at android.app.ActivityThread.main(ActivityThread.java:6111)         at java.lang.reflect.Method.invoke(Native Method)         at com.android.internal.os.ZygoteInit$  MethodAndArgsCaller.run(ZygoteInit.java:865)         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)      Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.stop()' on a null object reference         at com.app.trying.MainActivity.stopMediaPlayer(MainActivity.java:155)         at com.app.trying.MainActivity.onPause(MainActivity.java:150)         at android.app.Activity.performPause(Activity.java:6917)         at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323)         at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3724)         at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3701)          at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3675)          at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3649)          at android.app.ActivityThread.-wrap16(ActivityThread.java)          at android.app.ActivityThread$  H.handleMessage(ActivityThread.java:1487)          at android.os.Handler.dispatchMessage(Handler.java:102)          at android.os.Looper.loop(Looper.java:154)          at android.app.ActivityThread.main(ActivityThread.java:6111)          at java.lang.reflect.Method.invoke(Native Method)          at com.android.internal.os.ZygoteInit$  MethodAndArgsCaller.run(ZygoteInit.java:865)          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)  2019-05-09 19:13:43.736 2484-2484/? E/Launcher3: Meminfo, NativeHeapAllocatedSize18887424 2019-05-09 19:13:43.736 2484-2484/? E/Launcher3: Meminfo, NativeHeapSize35651584 2019-05-09 19:13:43.736 2484-2484/? E/Launcher3: Meminfo, getNativeHeapFreeSize16764160 2019-05-09 19:13:51.682 704-704/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 4 

How should I resolve this error? Any help would be great. Thanks.

(Dentro de una misma clase) ¿Cómo incluyo una función void dentro de una función bool?

¿Cómo puedo incluir el resultado de la función de void en la bool? necesito compararla, el error me recae en la función bool. Dice ‘No matching function for call to Fracción::elevarFraccionAlaN()’ Perdón si ven algo muy incoherente, soy nuevo programando. 😛

void elevarFraccionAlaN(int N){     float obtenerDivisionDecimal, Potencia, i;      i=1;     Potencia=1;      while(i<=N){         Potencia=Potencia*obtenerDivisionDecimal;         i++;     }    }   bool esMenorQue(){      if (elevarFraccionAlaN()<obtenerDivisionDecimal())         return true;     else return false; } 

¿Cómo incluir un void en un string toString (dentro de una clase C++)?

Antes que nada aclaro que soy nuevo programando, no llevo ni 2 meses. Bueno, esto que ven lo estoy escribiendo dentro de una clase, por si notan algo fuera de lo normal.

El caso es que la parte de “obtenerDivisiónDecimal()” me compila de maravilla.

Pero “elevarFracciónAlaN()” me salta un error diciendo “no matching function for call to Clase::elevarFraccionAlaN() Y básicamente es eso, me gustaría expresarlo mejor, pero no sé como. :c

string toString( ){   stringstream s;    s << "blablabla: " << obtenerDivisionDecimal( ) << endl;   s << "blablablah: " << elevarFraccionAlaN( ) << endl;    return s.str( ); }  float obtenerDivisionDecimal( ) {   return ( Numerador/Denominador ); }  void elevarFraccionAlaN( int N ) {   float elevarFraccionAlaN;    elevarFraccionAlaN = pow( ( Numerador / Denominador ), N );    return void ( elevarFraccionAlaN ); } 

Determining response codes from void functions OOP

I am trying to create a Put endpoint using rest. Let’s say that under the link

/addresses/12345 

I am trying to add a new address (if that id doesn’t exist) or I’m trying to update it if it does already exist.

My application has several layers Controllers, Services, Models and Repositories. Given the fact that the business layer decides if an update or an add is required (this logic takes place in the service layer and below), how would the controllers be able to find out if an update or an add happened and return the correct status codes (201 for resource created, 204 if just an update has occured)?

My only ideas are to return some sort of result object, but that doesn’t feel particularly correct. For the cases where the service methods are not void, they usually return DTOs.